package com.hctforgreen.greenservice.ctr;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.hctforgreen.greenservice.db.DBMessageManager;
import com.hctforgreen.greenservice.db.DbEntryAdapter;
import com.hctforgreen.greenservice.model.AssignLoginEntity;
import com.hctforgreen.greenservice.model.AttrEntity;
import com.hctforgreen.greenservice.model.BigUnitEntity;
import com.hctforgreen.greenservice.model.BigUnitPasswordStatusEntity;
import com.hctforgreen.greenservice.model.BookClickListEntity;
import com.hctforgreen.greenservice.model.BookListEntity;
import com.hctforgreen.greenservice.model.BookListEntity.BookEntity;
import com.hctforgreen.greenservice.model.BookTypeListEntity;
import com.hctforgreen.greenservice.model.BookZipTxtEntity;
import com.hctforgreen.greenservice.model.BookZipTxtEntity.EntryEntity;
import com.hctforgreen.greenservice.model.BootPasswordEntity;
import com.hctforgreen.greenservice.model.CheckVersionEntity;
import com.hctforgreen.greenservice.model.ColumnListEntity;
import com.hctforgreen.greenservice.model.ColumnListEntity.ColumnEntity;
import com.hctforgreen.greenservice.model.CompetInfoListEntity;
import com.hctforgreen.greenservice.model.DataVersionCodeEntity;
import com.hctforgreen.greenservice.model.EntryCatalogEntity;
import com.hctforgreen.greenservice.model.ExamPaperEntity;
import com.hctforgreen.greenservice.model.ExamSubEntity;
import com.hctforgreen.greenservice.model.FeedBackListEntity;
import com.hctforgreen.greenservice.model.LoadingInfoEntity;
import com.hctforgreen.greenservice.model.LoginResultEntity;
import com.hctforgreen.greenservice.model.MachineListEntity;
import com.hctforgreen.greenservice.model.MachineListEntity.MachineEntity;
import com.hctforgreen.greenservice.model.MessagesListEntity;
import com.hctforgreen.greenservice.model.MessagesListEntity.MessagesEntity;
import com.hctforgreen.greenservice.model.PersonPotinsEntity;
import com.hctforgreen.greenservice.model.PwdEntity;
import com.hctforgreen.greenservice.model.RelevanceEntity;
import com.hctforgreen.greenservice.model.ResultEntity;
import com.hctforgreen.greenservice.model.SerieListEntity;
import com.hctforgreen.greenservice.model.SerieListEntity.ChildSerieEntity;
import com.hctforgreen.greenservice.model.SerieListEntity.SerieEntity;
import com.hctforgreen.greenservice.model.SetupInfoEntity;
import com.hctforgreen.greenservice.model.SpareBootPasswordEntity;
import com.hctforgreen.greenservice.model.StudyEntity;
import com.hctforgreen.greenservice.model.SubmitBigUnitInfoEntity;
import com.hctforgreen.greenservice.model.SupportMidEntity;
import com.hctforgreen.greenservice.model.VersionCodeEntity;
import com.hctforgreen.greenservice.model.VideoTypeEntity;
import com.hctforgreen.greenservice.model.VideoTypeEntity.VideoDetailEntity;
import com.hctforgreen.greenservice.utils.BookZipTxtReaderUtil;
import com.hctforgreen.greenservice.utils.ContantsUtil;
import com.hctforgreen.greenservice.utils.DownloadBookLstInitFinishUtil;
import com.hctforgreen.greenservice.utils.HctConstants;
import com.hctforgreen.greenservice.utils.HctResult;
import com.hctforgreen.greenservice.utils.LogUtil;
import com.hctforgreen.greenservice.utils.LoginResultStoreUtil;
import com.hctforgreen.greenservice.utils.PersonPointsStoreUtil;
import com.hctforgreen.greenservice.utils.VersionUtil;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * NetAdapter的控制器
 *
 * @author Tallen Zhai
 */
public class HctController extends BaseController {
    private static final String TAG = "HctController";

    public HctController(Activity activity) {
        super(activity);
        context = activity;
    }

    public HctController(Context context) {
        super(context);
    }

    public HctController(DbEntryAdapter dbAdapter) {
        super(dbAdapter);
    }

    /**
     * 1、所有系列信息(不支持翻页)
     *
     * @return
     * @throws Exception
     */
    public HctResult getAllSeries(boolean bTopRefresh) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);

        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        SerieListEntity listEntity = null;
        if (!bTopRefresh) {
            /**
             * 首先尝试从db中查询
             */
            List<SerieEntity> serieEntities = selectSerieListFromDb();
            if (serieEntities.size() > 0) {
                listEntity = new SerieListEntity();
                listEntity.dataList = serieEntities;
            }
            /**
             * 查询不到则从服务器获取
             */
            else {
                listEntity = getAllSeriesFromNetAndInsert2Db(controller, params);
            }
        } else if (bTopRefresh) {
            listEntity = getAllSeriesFromNetAndInsert2Db(controller, params);
        }

        if (listEntity.dataList != null) {
            result.status = HctConstants.STATUS_SUCCESS;
            if (listEntity.dataList.size() > 0) {

                result.data = listEntity.dataList;
                result.totalSize = listEntity.dataList.size();
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 从服务器获取系列
     *
     * @param controller
     * @param params
     * @return
     * @throws Exception
     * @throws JSONException
     */
    private SerieListEntity getAllSeriesFromNetAndInsert2Db(
            HctBackTestJsonController controller,
            ArrayList<NameValuePair> params) throws Exception, JSONException {
        SerieListEntity listEntity;
        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_SYNC_DATA_MOBILE_PATH,
                        GET_ALL_SERIES_ACTION, params) : controller
                .getAllSeries();

        JSONObject jsonObject = new JSONObject(jsonString);

        listEntity = SerieListEntity.parse(jsonObject, context);

        if (listEntity.dataList != null) {
            insertSerieList2Db(listEntity);
        }
        return listEntity;
    }

    /**
     * 从db查询出"所有系列信息"
     *
     * @return
     */
    public List<SerieEntity> selectSerieListFromDb() {
        /**
         * 插入db
         */
        DbController dbController = new DbController(context);
        return dbController.getSerieEntityLst();
    }

    /**
     * 将获取到的"所有系列信息"插入db
     */
    private void insertSerieList2Db(SerieListEntity listEntity) {
        /**
         * 插入db
         */
        DbController dbController = new DbController(context);
        dbController.insert(listEntity);
    }

    /**
     * 2、所有机型信息(不支持翻页)
     *
     * @return
     * @throws Exception
     */
    public HctResult getAllMachines(boolean bTopRefresh) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);

        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        MachineListEntity listEntity = null;
        if (!bTopRefresh) {
            /**
             * 首先尝试从db中查询
             */
            List<MachineEntity> machineEntities = selectMachineListFromDb();
            if (machineEntities.size() > 0) {
                listEntity = new MachineListEntity();
                listEntity.dataList = machineEntities;
            }
            /**
             * 查询不到则从服务器获取
             */
            else {
                listEntity = getAllMachineFromNetAndInsert2Db(controller,
                        params);
            }
        } else if (bTopRefresh) {
            listEntity = getAllMachineFromNetAndInsert2Db(controller, params);
        }

        if (listEntity.dataList != null) {
            result.status = HctConstants.STATUS_SUCCESS;
            if (listEntity.dataList.size() > 0) {

                result.data = listEntity.dataList;
                result.totalSize = listEntity.dataList.size();
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    private MachineListEntity getAllMachineFromNetAndInsert2Db(
            HctBackTestJsonController controller,
            ArrayList<NameValuePair> params) throws Exception, JSONException {
        MachineListEntity listEntity;
        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_SYNC_DATA_MOBILE_PATH,
                        GET_ALL_MACHINES_ACTION, params) : controller
                .getAllMachines();

        JSONObject jsonObject = new JSONObject(jsonString);

        listEntity = MachineListEntity.parse(jsonObject);
        if (listEntity.dataList != null) {
            insertMachineList2Db(listEntity);
        }
        return listEntity;
    }

    /**
     * 从db查询出"所有机型信息"
     *
     * @return
     */
    private List<MachineEntity> selectMachineListFromDb() {
        /**
         * 插入db
         */
        DbController dbController = new DbController(context);
        return dbController.getMachineEntityLst("");
    }

    /**
     * 将获取到的"所有机型信息"插入db
     */
    private void insertMachineList2Db(MachineListEntity listEntity) {
        /**
         * 插入db
         */
        DbController dbController = new DbController(context);
        dbController.insert(listEntity);
    }

    /**
     * 3、所有资料类别信息(不支持翻页)
     *
     * @param seriesId 系列Id
     * @return
     * @throws Exception
     */
    @Deprecated
    public HctResult getAllBooktypes(boolean bTopRefresh) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);

        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_SYNC_DATA_MOBILE_PATH,
                        GET_ALL_BOOK_TYPES_ACTION, params) : controller
                .getAllBooktypes();

        JSONObject jsonObject = new JSONObject(jsonString);

        BookTypeListEntity listEntity = BookTypeListEntity.parse(jsonObject);
        if (listEntity.dataList != null) {
            result.status = HctConstants.STATUS_SUCCESS;
            if (listEntity.dataList.size() > 0) {
                result.data = listEntity.dataList;
                result.totalSize = listEntity.dataList.size();
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 4、根据系列ID获取资料(不支持翻页)
     *
     * @param seriesId
     * @return
     * @throws Exception
     */
    @Deprecated
    public HctResult getBooksBySeriesId(final String seriesId) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);

        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("seriesId", seriesId));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_SYNC_DATA_MOBILE_PATH,
                        GET_BOOKS_BY_SERIES_ID_ACTION, params) : controller
                .getBooksBySeriesId();

        JSONObject jsonObject = new JSONObject(jsonString);

        BookListEntity listEntity = BookListEntity.parse(jsonObject);
        if (listEntity.dataList != null) {
            result.status = HctConstants.STATUS_SUCCESS;
            if (listEntity.dataList.size() > 0) {
                result.data = listEntity.dataList;
                result.totalSize = listEntity.dataList.size();
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 用机型的childSeriesId查询到Book List
     *
     * @param machineEntity
     * @return
     * @throws Exception
     */
    public HctResult getDbBooksUseChildSeriesId(String seriesId,
                                                String childSeriesId) throws Exception {
        HctResult result = new HctResult();

        ChildSerieEntity cEntity = new ChildSerieEntity();

        cEntity.dataList = getBooksUseChildSeriesId(seriesId, childSeriesId);

        if (cEntity.dataList != null) {
            result.status = HctConstants.STATUS_SUCCESS;
            if (cEntity.dataList.size() > 0) {
                result.data = cEntity.dataList;
                result.totalSize = cEntity.dataList.size();
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    public SerieEntity selectSerieEntityFromDb(String seriesId) {
        DbController dbController = new DbController(context);
        return dbController.getSerieEntity(seriesId);
    }

    public HctResult getDbAllSeriesWithDbChildSeriesAndBooks() throws Exception {
        return getDbAllSeriesWithDbChildSeriesAndBooks(false);
    }

    /**
     * 从db查询出带有books的series列表
     *
     * @param bTechData 是否只要“技术资料”的book
     * @return
     * @throws Exception
     */
    public HctResult getDbAllSeriesWithDbChildSeriesAndBooks(
            final boolean bTechData) throws Exception {
        HctResult result = new HctResult();
        SerieListEntity listEntity = new SerieListEntity();
        /**
         * 首先尝试从db中查询
         */
        List<SerieEntity> serieEntities = selectSerieListFromDb();
        if (serieEntities.size() > 0) {

            for (SerieEntity serieEntity : serieEntities) {

                if (!bTechData) {
                    serieEntity.childList = getChildSerieListEntityAndBooksUseSerieId(serieEntity.id);
                } else if (bTechData) {
                    serieEntity.childList = getChildSerieListEntityAndTechDataBooksUseSerieId(serieEntity.id);
                }

                // serieEntity.dataList =
                // getBookListEntityUseSerieId(serieEntity.id).dataList;
            }
            listEntity.dataList = serieEntities;
        }
        if (listEntity.dataList != null) {
            result.status = HctConstants.STATUS_SUCCESS;
            if (listEntity.dataList.size() > 0) {
                result.data = listEntity.dataList;
                result.totalSize = listEntity.dataList.size();
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    private List<BookEntity> getBooksUseChildSeriesId(String seriesId,
                                                      String childSeriesId) {
        /**
         * 插入db
         */
        DbController dbController = new DbController(context);
        return dbController.getBooksUseChildSeriesId(seriesId, childSeriesId);
    }

    public List<ChildSerieEntity> getChildSerieListEntityUseSerieId(
            String seriesId, int type) {
        /**
         * 插入db
         */
        DbController dbController = new DbController(context);
        return dbController.getChildSerieListEntityUseSerieId(seriesId, type);
    }

    private List<ChildSerieEntity> getChildSerieListEntityAndTechDataBooksUseSerieId(
            String seriesId) {
        /**
         * 插入db
         */
        DbController dbController = new DbController(context);
        return dbController
                .getChildSerieListEntityAndTechDataBooksUseSerieId(seriesId);
    }

    /**
     * 根据系列ID获取ChildSerieEntity列表及BookEntity
     *
     * @param seriesId
     * @return
     */
    private List<ChildSerieEntity> getChildSerieListEntityAndBooksUseSerieId(
            String seriesId) {
        /**
         * 插入db
         */
        DbController dbController = new DbController(context);
        return dbController.getChildSerieListEntityAndBooksUseSerieId(seriesId);
    }

    private BookListEntity getBookListEntityUseSerieId(String seriesId, int type) {
        /**
         * 插入db
         */
        DbController dbController = new DbController(context);
        return dbController.getBookListEntityUseSerieId(seriesId, type);
    }

    /**
     * 调用4、获取所有资料，然后把资料拼凑进从db查询出的Series内部
     *
     * @param bTopRefresh 是否为下拉刷新
     * @return
     * @throws Exception
     */
    public HctResult getAllBooksWithDbAllSeries(boolean bTopRefresh, int type)
            throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);

        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        BookListEntity listEntity = null;
        if (!bTopRefresh) {
            /**
             * 首先尝试从db中查询
             */
            List<BookEntity> bookEntities = selectBookListFromDb(type).dataList;
            if (bookEntities != null && bookEntities.size() > 0) {
                listEntity = new BookListEntity();
                listEntity.dataList = bookEntities;
            }
            /**
             * 查询不到则从服务器获取
             */
            else {
                listEntity = getAllBooksFromNetAndInsert2Db(controller, params);
            }
        } else if (bTopRefresh) {
            listEntity = getAllBooksFromNetAndInsert2Db(controller, params);
        }

        if (listEntity.dataList != null) {
            result.status = HctConstants.STATUS_SUCCESS;
            if (listEntity.dataList.size() > 0) {

                SerieListEntity serieListEntity = null;
                /**
                 * 首先尝试从db中查询
                 */
                List<SerieEntity> serieEntities = selectSerieListFromDb();
                if (serieEntities.size() > 0) {
                    serieListEntity = new SerieListEntity();

                    for (SerieEntity serieEntity : serieEntities) {
                        for (BookEntity bookEntity : listEntity.dataList) {
                            if (bookEntity.seriesId.equals(serieEntity.id)) {
                                if (serieEntity.dataList == null) {
                                    serieEntity.dataList = new ArrayList<BookEntity>();
                                }
                                serieEntity.dataList.add(bookEntity);
                            }
                        }
                    }
                    serieListEntity.dataList = serieEntities;
                }

                result.data = serieListEntity.dataList;
                result.totalSize = serieListEntity.dataList.size();
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;

    }

    /**
     * 从net获取图书列表，然后将其拼凑进Db查询出的Series及ChildSeries内
     *
     * @param bTopRefresh
     * @return
     * @throws Exception
     */
    public HctResult getAllBooksWithDbAllSeriesAndAllChildSeries(
            boolean bTopRefresh, int type) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);

        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        BookListEntity listEntity = null;
        if (!bTopRefresh) {
            /**
             * 首先尝试从db中查询
             */
            List<BookEntity> bookEntities = selectBookListFromDb(type).dataList;
            if (bookEntities != null && bookEntities.size() > 0) {
                listEntity = new BookListEntity();
                listEntity.dataList = bookEntities;
            }
            /**
             * 查询不到则从服务器获取
             */
            else {
                listEntity = getAllBooksFromNetAndInsert2Db(controller, params);
            }
        } else if (bTopRefresh) {
            listEntity = getAllBooksFromNetAndInsert2Db(controller, params);
        }

        if (listEntity.dataList != null) {
            result.status = HctConstants.STATUS_SUCCESS;
            if (listEntity.dataList.size() > 0) {

                SerieListEntity serieListEntity = new SerieListEntity();
                List<SerieEntity> serieEntities = selectSerieListFromDb();
                if (serieEntities.size() > 0) {
                    for (SerieEntity serieEntity : serieEntities) {

                        serieEntity.childList = getChildSerieListEntityAndBooksUseSerieId(serieEntity.id);
                    }
                    serieListEntity.dataList = serieEntities;
                }

                result.data = serieListEntity.dataList;
                result.totalSize = serieListEntity.dataList.size();
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;

    }

    /**
     * 从服务器获取All Books，然后insert 到Db
     *
     * @param controller
     * @param params
     * @return
     * @throws Exception
     * @throws JSONException
     */
    private BookListEntity getAllBooksFromNetAndInsert2Db(
            HctBackTestJsonController controller,
            ArrayList<NameValuePair> params) throws Exception, JSONException {
        //Log.d("HctController", "开始从服务器获取All Books，然后insert 到Db");
        BookListEntity listEntity;
        params.add(new BasicNameValuePair("personId", LoginResultStoreUtil
                .get(context).personId));
        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_SYNC_DATA_MOBILE_PATH,
                        GET_ALL_BOOKS_ACTION, params) : controller
                .getAllBooks();

        JSONObject jsonObject = new JSONObject(jsonString);

        listEntity = BookListEntity.parse(jsonObject);
        if (listEntity != null) {
            insertBookList2Db(listEntity);
        }
        return listEntity;
    }

    /**
     * 从db查询出"所有books"
     *
     * @return
     */
    public BookListEntity selectBookListFromDb(int type) {
        /**
         * 插入db
         */
        DbController dbController = new DbController(context);
        return dbController.getBookListEntityUseSerieId("", type);
    }

    /**
     * 将获取到的"所有books"插入db
     */
    private void insertBookList2Db(BookListEntity listEntity) {
        /**
         * 插入db
         */
        DbController dbController = new DbController(context);
        dbController.insert(listEntity);
    }

    /**
     * 4、获取所有资料(不支持翻页)
     *
     * @param seriesId
     * @return
     * @throws Exception
     */
    public HctResult getAllBooks() throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);

        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("personId", LoginResultStoreUtil
                .get(context).personId));
        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_SYNC_DATA_MOBILE_PATH,
                        GET_ALL_BOOKS_ACTION, params) : controller
                .getAllBooks();

        JSONObject jsonObject = new JSONObject(jsonString);

        BookListEntity listEntity = BookListEntity.parse(jsonObject);
        if (listEntity.dataList != null) {
            result.status = HctConstants.STATUS_SUCCESS;
            if (listEntity.dataList.size() > 0) {
                result.data = listEntity.dataList;
                result.totalSize = listEntity.dataList.size();
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 派工账号登陆
     */
    public HctResult assignLogin(String phone) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("phone", phone));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_PERSON_MOBILE_PATH,
                        ASSIGN_LOGIN, params) : controller.appLogin();
        JSONObject jsonObject = new JSONObject(jsonString);

        AssignLoginEntity entity = AssignLoginEntity.parse(jsonObject);
        // PersonPotinsEntity potinsEntity =
        // PersonPotinsEntity.parse(jsonObject);
        // PersonPointsStoreUtil.save(context, potinsEntity);

        if (entity instanceof AssignLoginEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 获取验证码(解绑)
     *
     * @param phone
     * @param username
     * @param identityCode
     * @return
     * @throws Exception
     */
    public JSONObject getAccountActivateCode(String phone, String username,
                                             String identityCode) throws Exception {
        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("phone", phone));
        params.add(new BasicNameValuePair("userName", username));
        params.add(new BasicNameValuePair("identityCode", identityCode));

        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_ACCOUNT_MOBILE_PATH,
                GET_ACCOUNT_ACTIVATE_CODE_ACTION, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        return jsonObject;
    }

    /**
     * 获取验证码(首次登陆)
     *
     * @param phone
     * @param identityCode
     * @return
     * @throws Exception
     */
    public JSONObject getAccountActivateCode(String phone, String identityCode)
            throws Exception {
        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("phone", phone));
        params.add(new BasicNameValuePair("identityCode", identityCode));

        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_ACCOUNT_MOBILE_PATH, GET_ACTIVATE_CODE_ACTION,
                params);
        JSONObject jsonObject = new JSONObject(jsonString);
        return jsonObject;
    }

    /**
     * 账号解绑
     *
     * @param phone
     * @param username
     * @param identityCode
     * @param activeCode
     * @return
     * @throws Exception
     */
    public JSONObject compareActivateCode(String phone, String username,
                                          String identityCode, String activeCode) throws Exception {
        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("phone", phone));
        params.add(new BasicNameValuePair("userName", username));
        params.add(new BasicNameValuePair("identityCode", identityCode));
        params.add(new BasicNameValuePair("activeCode", activeCode));

        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_ACCOUNT_MOBILE_PATH,
                COMPARE_ACTIVATE_CODE_ACTION, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        return jsonObject;

    }

    /**
     * 6、用户登录
     *
     * @param phone      电话
     * @param onlyCode   唯一识别码
     * @param identity
     * @param activeCode
     * @param loginFlag  -true为云服务器
     * @return
     * @throws Exception
     */
    public HctResult appLogin(String phone, String onlyCode, String imeiCode,
                              String activeCode, String identity, int loginFlag) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("phone", phone));

        params.add(new BasicNameValuePair("onlyCode", onlyCode));

        params.add(new BasicNameValuePair("appVersion", VersionUtil
                .getAppVersionName(context)));
        params.add(new BasicNameValuePair("imeiCode", imeiCode));

        params.add(new BasicNameValuePair("appType", "Android"));

        if (!activeCode.equals("") && !identity.equals("")) {
            params.add(new BasicNameValuePair("activeCode", activeCode));
            params.add(new BasicNameValuePair("identityCode", identity));
        }
        /**
         * 2016-4-21 390694改
         */
        String jsonString = null;

        if (loginFlag >= 1) {// 访问云服务器
            jsonString = !controller.isB_DEBUG() ? mServerAdapter.invokeServerGetForCloud(
                    HctConstants.NET_PERSON_MOBILE_PATH, APP_LOGIN_ACTION_NEW, params) : controller.appLogin();

        } else {// 访问正式服务器
            jsonString = !controller.isB_DEBUG() ? mServerAdapter.invokeServerGet(HctConstants.NET_PERSON_MOBILE_PATH,
                            APP_LOGIN_ACTION_NEW, params) : controller.appLogin();
        }
        // String jsonString = !controller.isB_DEBUG() ? mServerAdapter
        // .invokeServerGet(HctConstants.NET_PERSON_MOBILE_PATH,
        // APP_LOGIN_ACTION, params) : controller.appLogin();
        JSONObject jsonObject = new JSONObject(jsonString);
        LoginResultEntity entity = LoginResultEntity.parse(jsonObject);
        // PersonPotinsEntity potinsEntity =
        // PersonPotinsEntity.parse(jsonObject);
        // PersonPointsStoreUtil.save(context, potinsEntity);
        LogUtil.i("DATA", "jsonString：" + jsonString);
        if (entity instanceof LoginResultEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 获取开机备用密码
     *
     * @param phone         电话
     * @param machineId     机型ID
     * @param province      省
     * @param city          城市
     * @param region        县\区
     * @param street        街道
     * @param projectName   工程名
     * @param owner         业主
     * @param ownerPhone    业主电话
     * @param remark        备注
     * @param isCloudServer -是否是云服务器，true-为云服务器
     * @return
     * @throws Exception
     */
    public HctResult getSpareBootPwd(PwdEntity entity, boolean isCloudServer)
            throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("phone", entity.phone));
        params.add(new BasicNameValuePair("barCodeId", entity.stripeCode));
        params.add(new BasicNameValuePair("mainAddress", entity.province
                + entity.city + entity.district));
        params.add(new BasicNameValuePair("detailAddress", entity.street));
        params.add(new BasicNameValuePair("projectName", entity.projectName));
        params.add(new BasicNameValuePair("owner", entity.ownerName));
        params.add(new BasicNameValuePair("ownerPhone", entity.ownerPhone));
        params.add(new BasicNameValuePair("industry", entity.industry));
        params.add(new BasicNameValuePair("remark", entity.remark));

        // String jsonString =
        // mServerAdapter.invokeServerPost(HctConstants.NET_SPARE_BOOT_MOBILE_PATH,GET_SPARE_BOOT_PWD_ACTION,
        // params);

        String jsonString = null;
        if (isCloudServer) {// 云服务器
            jsonString = mServerAdapter.invokeServerGetForCloud(
                    HctConstants.NET_SPARE_BOOT_MOBILE_PATH,
                    GET_SPARE_BOOT_PWD_ACTION, params);
        } else {// 正式服务器
            jsonString = mServerAdapter.invokeServerGet(
                    HctConstants.NET_SPARE_BOOT_MOBILE_PATH,
                    GET_SPARE_BOOT_PWD_ACTION, params);
        }

        JSONObject jsonObject = new JSONObject(jsonString);

        SpareBootPasswordEntity bean = SpareBootPasswordEntity
                .parse(jsonObject);

        if (bean instanceof SpareBootPasswordEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = bean;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;

    }

    /**
     * 7、获取开机密码
     *
     * @param phone              电话
     * @param barCodeId          机型ID
     * @param gpsLocation        Gps定位
     * @param baseLocation       基站定位
     * @param wifiLocation       网络定位
     * @param province           省
     * @param city               城市
     * @param region             县\区
     * @param street             街道
     * @param projectName        工程名
     * @param owner              业主
     * @param ownerPhone         业主电话
     * @param remark             备注
     * @param ioConnectionLength
     * @param dropHeight
     * @param inDropHeight
     * @param tubeLength
     * @param addCoolantWeight
     * @param diameter
     * @param isClounServer      ---服务器类型,false为正式服务器，true为云服务器
     * @return
     * @throws Exception
     */
    public HctResult getBootPwd(String phone, String barCodeId,
                                String gpsLocation, String baseLocation, String wifiLocation,
                                String locProvince, String locCity, String province, String city,
                                String region, String street, String projectName, String owner,
                                String ownerPhone, String remark, String industry,
                                String ioConnectionLength, String dropHeight, String inDropHeight,
                                String tubeLength, String addCoolantWeight, String diameter,
                                String matchWaterbox, String installationSite,
                                String constructionArea, String crossCode, String latitude,
                                String longitude, String operationSite, boolean isClounServer)
            throws Exception {
        HctResult result = new HctResult();
        HctBackTestJsonController controller = new HctBackTestJsonController(context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("phone", phone));
        params.add(new BasicNameValuePair("barCodeId", barCodeId));
        if (gpsLocation != null && !"".equals(gpsLocation.trim())) {
            params.add(new BasicNameValuePair("gpsLocation", gpsLocation));
        }
        if (baseLocation != null && !"".equals(baseLocation.trim())) {
            params.add(new BasicNameValuePair("baseLocation", baseLocation));
        }
        if (wifiLocation != null && !"".equals(wifiLocation.trim())) {
            params.add(new BasicNameValuePair("wifiLocation", wifiLocation));
        }
        if (!TextUtils.isEmpty(operationSite)) {
            params.add(new BasicNameValuePair("operationSite", operationSite));
        }
        if (!TextUtils.isEmpty(crossCode)) {
            params.add(new BasicNameValuePair("crossCode", crossCode));
        }
        if (ioConnectionLength != null && ioConnectionLength.trim().length() > 0) {
            params.add(new BasicNameValuePair("ioConnectionLength", ioConnectionLength));
        }
        if (dropHeight != null && dropHeight.trim().length() > 0) {
            params.add(new BasicNameValuePair("dropHeight", dropHeight));
        }
        if (inDropHeight != null && inDropHeight.trim().length() > 0) {
            params.add(new BasicNameValuePair("inDropHeight", inDropHeight));
        }
        if (tubeLength != null && tubeLength.trim().length() > 0) {
            params.add(new BasicNameValuePair("tubeLength", tubeLength));
        }
        if (addCoolantWeight != null && addCoolantWeight.trim().length() > 0) {
            params.add(new BasicNameValuePair("addCoolantWeight", addCoolantWeight));
        }
        if (diameter != null && diameter.trim().length() > 0) {
            params.add(new BasicNameValuePair("diameter", diameter));
        }
        if (matchWaterbox != null && matchWaterbox.trim().length() > 0) {
            params.add(new BasicNameValuePair("matchWaterbox", matchWaterbox));
        }
        if (installationSite != null && installationSite.trim().length() > 0) {
            params.add(new BasicNameValuePair("installationSite", installationSite));
        }
        if (constructionArea != null && constructionArea.trim().length() > 0) {
            params.add(new BasicNameValuePair("constructionArea", constructionArea));
        }
        params.add(new BasicNameValuePair("latitude", latitude));
        params.add(new BasicNameValuePair("longitude", longitude));
        params.add(new BasicNameValuePair("bakProvince", locProvince));
        params.add(new BasicNameValuePair("bakCity", locCity));
        params.add(new BasicNameValuePair("province", province));
        params.add(new BasicNameValuePair("city", city));
        params.add(new BasicNameValuePair("region", region));
        params.add(new BasicNameValuePair("street", street));
        params.add(new BasicNameValuePair("projectName", projectName));
        params.add(new BasicNameValuePair("owner", owner));
        params.add(new BasicNameValuePair("ownerPhone", ownerPhone));
        params.add(new BasicNameValuePair("industry", industry));
        if (!remark.equals("")) {
            params.add(new BasicNameValuePair("remark", remark));
        }

        String jsonString = null;
        if (isClounServer) {
            // true--云服务器
            // 如果是Debug，则使用模拟数据

            jsonString = !controller.isB_DEBUG() ? mServerAdapter
                    .invokeServerPostForClound(
                            HctConstants.NET_BOOT_MOBILE_PATH,
                            GET_BOOT_PWD_ACTION, params) : controller
                    .getBootPwd();

        } else {
            // fase--正式服务器
            // 如果是Debug，则使用模拟数据
            jsonString = !controller.isB_DEBUG() ? mServerAdapter.invokeServerPost(HctConstants.NET_BOOT_MOBILE_PATH,
                    GET_BOOT_PWD_ACTION, params) : controller.getBootPwd();
        }

        LogUtil.e("DATA", "获取开机密码---" + jsonString);

        JSONObject jsonObject = new JSONObject(jsonString);

        BootPasswordEntity entity = BootPasswordEntity.parse(jsonObject);

        if (entity instanceof BootPasswordEntity) {
            result.status = HctConstants.STATUS_SUCCESS;
            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 提交大机组信息
     *
     * @param mBigUnitEntity
     * @param isClounServer  -- true为正式服务器
     * @return
     * @throws Exception
     */
    @SuppressWarnings("static-access")
    public HctResult submitBigUnitInfo(BigUnitEntity mBigUnitEntity,
                                       String gpsLocation, String baseLocation, String wifiLocation,
                                       boolean isClounServer) throws Exception {
        HctResult result = new HctResult();
        HctBackTestJsonController controller = new HctBackTestJsonController(context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params = mBigUnitEntity.getBigUnitDataArrayList();
        /*
         * Log.i("DATA", "gpsLocation==" + gpsLocation); Log.i("DATA",
         * "baseGPS==" + baseLocation); Log.i("DATA", "wifiLocation==" +
         * wifiLocation);
         */
        if (gpsLocation != null && !"".equals(gpsLocation.trim())) {
            params.add(new BasicNameValuePair("gpsLocation", gpsLocation));
        }
        if (baseLocation != null && !"".equals(baseLocation.trim())) {
            params.add(new BasicNameValuePair("baseGPS", baseLocation));
        }
        if (wifiLocation != null && !"".equals(wifiLocation.trim())) {
            params.add(new BasicNameValuePair("wifiLocation", wifiLocation));
        }
        /*
         * for (int i = 0; i < params.size(); i++) { Log.i("DATA",
         * params.get(i).getValue()); }
         */
        String jsonString = null;
        if (isClounServer) {
            // true--云服务器
            // 如果是Debug，则使用模拟数据
            // Log.i("DATA", "执行submitBigUnitInfo（）----" + "云1");
            jsonString = !controller.isB_DEBUG() ? mServerAdapter.invokeServerPostForClound(
                    HctConstants.NET_LARGEUNIT_BOOT_MOBILE_PATH,
                    SUBMIT_LARGEUNITINFO_ACTION, params) : controller.getBootPwd();
            // Log.i("DATA", "执行submitBigUnitInfo（）----" + "云");
        } else {
            // fase--正式服务器
            // 如果是Debug，则使用模拟数据
            // Log.i("DATA", "执行submitBigUnitInfo（）----" + "正式1");
            jsonString = !controller.isB_DEBUG() ? mServerAdapter.invokeServerPost(
                    HctConstants.NET_LARGEUNIT_BOOT_MOBILE_PATH,
                    SUBMIT_LARGEUNITINFO_ACTION, params) : controller.getBootPwd();
            // Log.i("DATA", "执行submitBigUnitInfo（）----" + "正式");
        }
        // Log.i("DATA", "执行submitBigUnitInfo（）----" + jsonString);
        JSONObject jsonObject = new JSONObject(jsonString);
        SubmitBigUnitInfoEntity entity = SubmitBigUnitInfoEntity.parse(jsonObject);
        if (entity instanceof SubmitBigUnitInfoEntity) {
            result.status = HctConstants.STATUS_SUCCESS;
            result.isBigUnit = true;
            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 获取大机组开机密码审核状态
     *
     * @param mBigUnitEntity
     * @return
     * @throws Exception
     */
    @SuppressWarnings("static-access")
    public HctResult getStatusForBigUnitPwd(String phone, String personId,
                                            boolean isCloundServer) throws Exception {

        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<BigUnitPasswordStatusEntity> dataList = new ArrayList<BigUnitPasswordStatusEntity>();

        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("phone", phone));
        params.add(new BasicNameValuePair("personId", personId));

        // for (int i = 0; i < params.size(); i++) {
        // Log.i("DATA", params.get(i).getValue());
        // }
        String jsonString = null;
        if (isCloundServer) {
            // true--云服务器
            // 如果是Debug，则使用模拟数据
            jsonString = !controller.isB_DEBUG() ? mServerAdapter
                    .invokeServerPostForClound(
                            HctConstants.NET_LARGEUNIT_BOOT_MOBILE_PATH,
                            GET_LARGEUNIT_REVIEW_STATUS_ACTION, params)
                    : controller.getBootPwd();
        } else {
            // fase--正式服务器
            // 如果是Debug，则使用模拟数据
            jsonString = !controller.isB_DEBUG() ? mServerAdapter
                    .invokeServerPost(
                            HctConstants.NET_LARGEUNIT_BOOT_MOBILE_PATH,
                            GET_LARGEUNIT_REVIEW_STATUS_ACTION, params)
                    : controller.getBootPwd();
        }
        LogUtil.i("DATA", "大机组=" + jsonString);
        JSONObject jsonObject = new JSONObject(jsonString);

        BigUnitPasswordStatusEntity entity = BigUnitPasswordStatusEntity
                .parse(jsonObject);

        if (entity instanceof BigUnitPasswordStatusEntity) {
            if (entity.statusCode.equals("0")) {
                result.status = HctConstants.STATUS_SUCCESS;
                dataList = entity.parseJSONForBigUnit(jsonObject);
                result.data = dataList;
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }

        } else {
            result.status = HctConstants.STATUS_FAILD;
            // Log.i("DATA", "执行submitBigUnitInfo（）--7" + result.status);
        }

        return result;
    }

    /**
     * 大机组报完成
     *
     * @param personId
     * @param phone
     * @param identityCode
     * @param stripeCode
     * @param finished
     * @return
     * @throws Exception
     */
    public HctResult BigUnitComplete(String personId, String phone,
                                     String identityCode, String stripeCode, String finished,
                                     boolean isCloudServer) throws Exception {
        HctResult result = new HctResult();
        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);

        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("phone", phone));
        params.add(new BasicNameValuePair("personId", personId));
        params.add(new BasicNameValuePair("identityCode", identityCode));
        params.add(new BasicNameValuePair("barcode", stripeCode));
        params.add(new BasicNameValuePair("finished", finished));

        String jsonString = null;

        if (isCloudServer) {// 云服务器
            jsonString = !controller.isB_DEBUG() ? mServerAdapter
                    .invokeServerPostForClound(
                            HctConstants.NET_LARGEUNIT_BOOT_MOBILE_PATH,
                            SUBMIT_CONFIRM_ACTION, params) : controller
                    .getBootPwd();
        } else {// 正式服务器
            jsonString = !controller.isB_DEBUG() ? mServerAdapter
                    .invokeServerPost(
                            HctConstants.NET_LARGEUNIT_BOOT_MOBILE_PATH,
                            SUBMIT_CONFIRM_ACTION, params) : controller
                    .getBootPwd();
        }
        // Log.i("DATA", "执行submitBigUnitInfo（）---5" + jsonString);

        JSONObject jsonObject = new JSONObject(jsonString);

        SubmitBigUnitInfoEntity entity = SubmitBigUnitInfoEntity
                .parse(jsonObject);
        if (entity instanceof SubmitBigUnitInfoEntity) {
            result.status = HctConstants.STATUS_SUCCESS;
            result.data = entity;

        } else {
            result.status = HctConstants.STATUS_FAILD;

        }

        return result;

    }

    /**
     * 获取开机密码的提醒及关联的资料
     *
     * @throws Exception
     */
    public HctResult getRelevanceHint(String machineId) throws Exception {

        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("machineId", machineId));

        String jsonString = mServerAdapter.invokeServerPostForAssociation(
                HctConstants.NET_BOOT_MOBILE_PATH, GET_RELEVANCE_HINT, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        LogUtil.i("DATA", "getRelevanceHint" + jsonObject);
        RelevanceEntity entity = RelevanceEntity.getInstance().parse(jsonObject);
        LogUtil.i("DATA", "getRelevanceHint result=" + JSON.toJSONString(entity));
        if (entity instanceof RelevanceEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;

    }

    /**
     * 信息反馈
     *
     * @param context
     * @param userName
     * @param userId
     * @param feeType  知识类型(如果为零，则为软件反馈)
     * @return
     * @throws Exception
     */
    @Deprecated
    public HctResult addFee(String mcontext, String userName, String userId,
                            String feeType) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("context", mcontext));

        params.add(new BasicNameValuePair("userName", userName));

        params.add(new BasicNameValuePair("userId", userId));

        params.add(new BasicNameValuePair("feeType", feeType));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_PERSON_MOBILE_PATH,
                        ADD_FEE_ACTION, params) : controller.addFee();
        JSONObject jsonObject = new JSONObject(jsonString);

        ResultEntity entity = ResultEntity.parse(jsonObject);

        if (entity instanceof ResultEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 版本控制
     *
     * @param code
     * @param channel
     * @return
     * @throws Exception
     */
    @Deprecated
    public HctResult getVersionCode(String code) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("code", code));

        params.add(new BasicNameValuePair("sys", "an"));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_PERSON_MOBILE_PATH,
                        GET_VERSION_CODE_ACTION, params) : controller
                .getVersionCode();
        JSONObject jsonObject = new JSONObject(jsonString);

        VersionCodeEntity entity = VersionCodeEntity.parse(jsonObject);

        if (entity instanceof VersionCodeEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 8、提交文本反馈
     *
     * @param personId
     * @param seriesId
     * @param topic
     * @param content
     * @param filepaths
     * @return
     * @throws Exception
     */
    public HctResult submitFeedBack(String personId, String seriesId,
                                    String topic, String content, List<String> filepaths,
                                    List<String> videoPathes, String attachment, String applianceType,
                                    String feedbackType, String barCode) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("personId", personId));

        params.add(new BasicNameValuePair("seriesId", seriesId));

        params.add(new BasicNameValuePair("topic", topic));

        params.add(new BasicNameValuePair("content", content));
        params.add(new BasicNameValuePair("applianceType", applianceType));
        params.add(new BasicNameValuePair("feedbackType", feedbackType));
        params.add(new BasicNameValuePair("barcode", barCode));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerPostPhoto(HctConstants.NET_FEEDBACK_MOBILE_PATH,
                        SUBMIT_FEEDBACK_ACTION, params, filepaths, videoPathes,
                        attachment) : controller.submitFeedBack();
        JSONObject jsonObject = new JSONObject(jsonString);

        // Log.i("hlp", "barCode=="+barCode);
        // Log.i("hlp", jsonObject.toString());

        ResultEntity entity = ResultEntity.parse(jsonObject);

        if (entity instanceof ResultEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 提交章节意见
     *
     * @param personId
     * @param entryTitleId
     * @param content
     * @return
     * @throws Exception
     */
    public HctResult submitAdvice(String personId, String entryTitleId,
                                  String content) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("personId", personId));

        params.add(new BasicNameValuePair("entryTitleId", entryTitleId));

        params.add(new BasicNameValuePair("content", content));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerPost(HctConstants.NET_CHAPTER_MOBILE_PATH,
                        SUBMIT_CHAPTER_SUGGEST_ACTION, params) : controller
                .submitFeedBack();
        JSONObject jsonObject = new JSONObject(jsonString);

        ResultEntity entity = ResultEntity.parse(jsonObject);

        if (entity instanceof ResultEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 提交书籍意见
     *
     * @param personId
     * @param entryTitleId
     * @param content
     * @return
     * @throws Exception
     */
    public HctResult submitBookAdvice(String personId, String bookId,
                                      String content) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("personId", personId));

        params.add(new BasicNameValuePair("bookId", bookId));

        params.add(new BasicNameValuePair("content", content));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerPost(HctConstants.NET_BOOK_MOBILE_PATH,
                        SUBMIT_BOOK_SUGGEST, params) : controller
                .submitFeedBack();
        JSONObject jsonObject = new JSONObject(jsonString);

        ResultEntity entity = ResultEntity.parse(jsonObject);

        if (entity instanceof ResultEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 追加反馈回复
     * <p>
     * feedback-mobile!addFeedbackMessage.do
     *
     * @param personId
     * @param feedbackId
     * @param content
     * @return
     * @throws Exception
     */
    public HctResult addFeedbackMessage(String personId, String feedbackId,
                                        String content) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("personId", personId));

        params.add(new BasicNameValuePair("feedbackId", feedbackId));

        params.add(new BasicNameValuePair("content", content));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerPost(HctConstants.NET_FEEDBACK_MOBILE_PATH,
                        ADD_FEEDBACK_MESSAGE_ACTION, params) : controller
                .submitFeedBack();
        JSONObject jsonObject = new JSONObject(jsonString);

        ResultEntity entity = ResultEntity.parse(jsonObject);

        if (entity instanceof ResultEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    // feedback-mobile!submitScore.do

    /**
     * 提交反馈评分
     * <p>
     * feedback-mobile!addFeedbackMessage.do
     *
     * @param feedbackId
     * @param score      0顶 1踩
     * @return
     * @throws Exception
     */
    public HctResult submitScore(String feedbackId, String score)
            throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("score", score));
        params.add(new BasicNameValuePair("id", feedbackId));

        String jsonString = controller.isB_DEBUG() ? controller
                .submitFeedBack() : mServerAdapter
                .invokeServerPost(HctConstants.NET_FEEDBACK_MOBILE_PATH,
                        SUBMIT_SCORE_ACTION, params);
        JSONObject jsonObject = new JSONObject(jsonString);

        ResultEntity entity = ResultEntity.parse(jsonObject);

        if (entity instanceof ResultEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 2016 11 23 390778
     * 提交点赞操作
     */
    public HctResult submitPraise(String personId, String bookId, String score) throws Exception {
        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        HctResult result = new HctResult();
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("studyId", bookId));
        params.add(new BasicNameValuePair("personId", personId));
        String jsonString = "";
        if (score.equals("1")) {
            jsonString = mServerAdapter.invokeServerPost(
                    HctConstants.NET_STATISTICS_MOBILE_PATH, SUBMIT_PRAISE, params);
        } else {
            jsonString = mServerAdapter.invokeServerPost(
                    HctConstants.NET_STATISTICS_MOBILE_PATH, SUBMIT_STEP, params);
        }
        JSONObject jsonObject = new JSONObject(jsonString);

        ResultEntity entity = ResultEntity.parse(jsonObject);
        if (entity instanceof ResultEntity) {
            result.status = HctConstants.STATUS_SUCCESS;
            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 9、提交电话反馈
     *
     * @param score
     * @param scoreContent
     * @param personId
     * @param timeLength
     * @return
     * @throws Exception
     */
    public HctResult submitPhoneFeedBack(String score, String scoreContent,
                                         String personId, String timeLength) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("score", score));

        params.add(new BasicNameValuePair("scoreContent", scoreContent));

        params.add(new BasicNameValuePair("personId", personId));

        params.add(new BasicNameValuePair("timeLength", timeLength));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_PHONE_FEEDBACK_MOBILE_PATH,
                        SUBMIT_PHONE_FEEDBACK_ACTION, params) : controller
                .submitPhoneFeedBack();
        JSONObject jsonObject = new JSONObject(jsonString);

        ResultEntity entity = ResultEntity.parse(jsonObject);

        if (entity instanceof ResultEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * FIXME 10、根据用户Id获取反馈信息(不支持翻页)
     *
     * @param personId
     * @return
     * @throws Exception
     */
    public HctResult getFeedBackJsonByPersonId(String personId, String pageNum)
            throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair(PAGE_SIZE, String
                .valueOf(HctConstants.PAGE_SIZE)));
        params.add(new BasicNameValuePair(PAGE_NUM, String.valueOf(pageNum)));

        params.add(new BasicNameValuePair("personId", personId));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_FEEDBACK_MOBILE_PATH,
                        GET_FEEDBACK_JSON_BY_PERSION_ID_ACTION, params)
                : controller.getFeedBackJsonByPersonId();
        JSONObject jsonObject = new JSONObject(jsonString);
        LogUtil.i("DATA", "我的反馈 =" + jsonString);
        FeedBackListEntity listEntity = FeedBackListEntity.parse(jsonObject);

        if (listEntity.dataList != null) {
            result.status = HctConstants.STATUS_SUCCESS;
            if (listEntity.dataList.size() > 0) {
                result.phone = listEntity.phone;
                result.data = listEntity.dataList;
                if (hasNextPage(listEntity.dataList.size())) {
                    result.totalSize = Integer.MAX_VALUE;
                } else {
                    result.totalSize = listEntity.dataList.size();
                }

                if (pageNum.equals("1")) {
                    DbFeedBackController dbFeedBackController = new DbFeedBackController(
                            context);
                    dbFeedBackController.insert(listEntity);
                }
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * FIXME 获取公开案例
     *
     * @param personId
     * @return
     * @throws Exception
     */
    public HctResult getOpencaseJsonByPersonId(String personId, String pageNum)
            throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair(PAGE_SIZE, String
                .valueOf(HctConstants.PAGE_SIZE)));
        params.add(new BasicNameValuePair(PAGE_NUM, String.valueOf(pageNum)));

        params.add(new BasicNameValuePair("personId", personId));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_OPENCASE_MOBILE_PATH,
                        GET_OPENCASE_JSON_BY_PERSONID_ACTION, params)
                : controller.getFeedBackJsonByPersonId();
        JSONObject jsonObject = new JSONObject(jsonString);

        FeedBackListEntity listEntity = FeedBackListEntity.parse(jsonObject);

        if (listEntity.dataList != null) {
            result.status = HctConstants.STATUS_SUCCESS;
            if (listEntity.dataList.size() > 0) {
                result.phone = listEntity.phone;
                result.data = listEntity.dataList;
                if (hasNextPage(listEntity.dataList.size())) {
                    result.totalSize = Integer.MAX_VALUE;
                } else {
                    result.totalSize = listEntity.dataList.size();
                }
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 获取视频列表
     */
    public HctResult getVideoTypeList(String personId) throws Exception {
        HctResult result = new HctResult();
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("personId", personId));
        String jsonString = mServerAdapter.invokeServerPost(
                HctConstants.NET_VIDEO_MOBILE_PATH, GET_ALL_VIDEOS_ACTION,
                params);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject != null && jsonObject.has("list")) {
            result.status = HctConstants.STATUS_SUCCESS;
            JSONArray jsonArray = jsonObject.getJSONArray("list");
            if (jsonArray != null && jsonArray.length() > 0) {
                ArrayList<VideoTypeEntity> videoTypeEntities = new ArrayList<VideoTypeEntity>();
                for (int i = 0; i < jsonArray.length(); i++) {
                    videoTypeEntities.add(VideoTypeEntity.parse(jsonArray
                            .getJSONObject(i)));
                }
                result.data = videoTypeEntities;
                result.totalSize = videoTypeEntities.size();
            }

        } else {
            result.status = HctConstants.STATUS_FAILD;
            if (jsonObject.has("msg")) {
                result.message = jsonObject.getString("msg");
            }
        }

        return result;
    }

    /**
     * 获取类型下面的所有视频
     */
    public HctResult getAllVideosByTypeId(String typeId, String personId,
                                          int pageNum) throws Exception {
        HctResult result = new HctResult();
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("typeId", typeId));
        params.add(new BasicNameValuePair("personId", personId));
        params.add(new BasicNameValuePair("pageNum", pageNum + ""));
        params.add(new BasicNameValuePair("pageSize", HctConstants.PAGE_SIZE
                + ""));
        String jsonString = mServerAdapter.invokeServerPost(
                HctConstants.NET_VIDEO_MOBILE_PATH,
                GET_ALL_VIDEOS_BY_TYPEID_ACTION, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject != null && jsonObject.has("list")) {
            result.status = HctConstants.STATUS_SUCCESS;
            JSONArray jsonArray = jsonObject.getJSONArray("list");
            if (jsonArray != null && jsonArray.length() > 0) {
                ArrayList<VideoTypeEntity> videoTypeEntities = new ArrayList<VideoTypeEntity>();
                for (int i = 0; i < jsonArray.length(); i++) {
                    videoTypeEntities.add(VideoTypeEntity.parse(jsonArray
                            .getJSONObject(i)));
                }
                result.data = videoTypeEntities;
                result.totalSize = videoTypeEntities.size();
            }

        } else {
            result.status = HctConstants.STATUS_FAILD;
            if (jsonObject.has("msg")) {
                result.message = jsonObject.getString("msg");
            }
        }

        return result;
    }

    /**
     * 根据关键字搜索视频
     */
    public HctResult searchVideoByCriteria(String searchCriteria,
                                           String personId, int pageNum) throws Exception {
        HctResult result = new HctResult();
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("searchCriteria", searchCriteria));
        params.add(new BasicNameValuePair("personId", personId));
        params.add(new BasicNameValuePair("pageNum", pageNum + ""));
        params.add(new BasicNameValuePair("pageSize", HctConstants.PAGE_SIZE
                + ""));
        String jsonString = mServerAdapter.invokeServerPost(
                HctConstants.NET_VIDEO_MOBILE_PATH,
                SEARCH_VIDEO_BY_CRITERIA_ACTION, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject != null && jsonObject.has("list")) {
            result.status = HctConstants.STATUS_SUCCESS;
            JSONArray jsonArray = jsonObject.getJSONArray("list");
            if (jsonArray != null && jsonArray.length() > 0) {
                ArrayList<VideoTypeEntity> videoTypeEntities = new ArrayList<VideoTypeEntity>();
                for (int i = 0; i < jsonArray.length(); i++) {
                    videoTypeEntities.add(VideoTypeEntity.parse(jsonArray
                            .getJSONObject(i)));
                }
                result.data = videoTypeEntities;
                result.totalSize = videoTypeEntities.size();
            }

        } else {
            result.status = HctConstants.STATUS_FAILD;
            if (jsonObject.has("msg")) {
                result.message = jsonObject.getString("msg");
            }
        }

        return result;
    }

    /**
     * 获取视频详情
     */
    public HctResult getVideoDetailById(String id) throws Exception {
        HctResult result = new HctResult();
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("id", id));
        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_VIDEO_MOBILE_PATH,
                GET_VIDEO_DETAIL_BY_ID_ACTION, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        result.status = HctConstants.STATUS_SUCCESS;
        result.data = VideoDetailEntity.parse(jsonObject);

        return result;
    }

    /**
     * 12、获取最新通知列表
     *
     * @return
     * @throws Exception
     */
    public HctResult getRecentMessages() throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);

        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        LoginResultEntity resultEntity = LoginResultStoreUtil.get(context);

        params.add(new BasicNameValuePair("personId", resultEntity.personId));
        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_MESSAGE_MOBILE_PATH,
                        GET_RECENT_MESSAGES_ACTION, params) : controller
                .getRecentMessages();
        JSONObject jsonObject = new JSONObject(jsonString);

        MessagesListEntity listEntity = MessagesListEntity.parse(jsonObject, 1);

        if (listEntity.dataList != null) {
            DBMessageManager dbMessageManager = new DBMessageManager(context);
            result.status = HctConstants.STATUS_SUCCESS;
            if (listEntity.dataList.size() > 0) {
                List<MessagesEntity> deleteList = new ArrayList<MessagesListEntity.MessagesEntity>();
                List<MessagesEntity> daolist = dbMessageManager.queryAll();
                if (daolist != null && !daolist.isEmpty()) {
                    for (MessagesEntity messagesEntity : daolist) {
                        if (!hasMsg(listEntity.dataList, messagesEntity)) {
                            deleteList.add(messagesEntity);
                        }
                    }
                    if (!deleteList.isEmpty()) {
                        dbMessageManager.delete(deleteList);
                    }
                }
                dbMessageManager.add(listEntity.dataList);
                // for (MessagesEntity messagesEntity : listEntity.dataList) {
                // if (hasMsg(daolist, messagesEntity)) {
                //
                // } else {
                // insertList.add(messagesEntity);
                // }
                //
                // }

            }
            List<MessagesEntity> reData = dbMessageManager.queryThreeMsg();
            result.data = reData;
            result.totalSize = reData.size();

        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * @param list
     * @param msg
     * @return
     */

    private static boolean hasMsg(List<MessagesEntity> list, MessagesEntity msg) {
        if (list == null || list.isEmpty() || msg == null) {
            return false;
        }
        int index = 0;
        for (MessagesEntity messagesEntity : list) {
            if (messagesEntity.id.equals(msg.id)) {
                index++;
                break;
            }
        }

        return index > 0;
    }

    /**
     * 13、获取通知列表(支持翻页)
     *
     * @param dateFrom 日期
     * @param pageNum  第几页开始
     * @param pageSize
     * @param type     类型
     * @param seriesId 机组型号
     * @return
     * @throws Exception
     */
    public HctResult getMessagesFromDate(String dateFrom, String pageNum,
                                         String type, String seriesId, String keywords) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        LoginResultEntity resultEntity = LoginResultStoreUtil.get(context);

        params.add(new BasicNameValuePair("personId", resultEntity.personId));
        params.add(new BasicNameValuePair(PAGE_SIZE, String
                .valueOf(HctConstants.PAGE_SIZE)));
        params.add(new BasicNameValuePair(PAGE_NUM, String.valueOf(pageNum)));
        params.add(new BasicNameValuePair("type", String.valueOf(type)));
        if (!"".equals(dateFrom.trim())) {
            params.add(new BasicNameValuePair("dateFrom", String
                    .valueOf(dateFrom)));
        }
        if (!TextUtils.isEmpty(keywords)) {
            params.add(new BasicNameValuePair("keywords", keywords));
        }

        if (/* seriesId != null && */!"".equals(seriesId.trim())) {
            params.add(new BasicNameValuePair("seriesId", String
                    .valueOf(seriesId)));
        }

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_MESSAGE_MOBILE_PATH,
                        GET_MESSAGES_FROM_DATE_ACTION, params) : controller
                .getMessagesFromDate();
        JSONObject jsonObject = new JSONObject(jsonString);

        MessagesListEntity listEntity = MessagesListEntity.parse(jsonObject, 0);

        if (listEntity.dataList != null) {
            DBMessageManager dbMessageManager = new DBMessageManager(context);
            dbMessageManager.add(listEntity.dataList);
            for (int i = 0; i < listEntity.dataList.size(); i++) {
                MessagesEntity entity = listEntity.dataList.get(i);
                dbMessageManager.setMessageReadStatus(entity);
            }

            result.status = HctConstants.STATUS_SUCCESS;
            if (listEntity.dataList.size() > 0) {
                result.data = listEntity.dataList;

                if (hasNextPage(listEntity.dataList.size())) {
                    result.totalSize = Integer.MAX_VALUE;
                } else {
                    result.totalSize = listEntity.dataList.size();
                }
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 判断是否还有下一页数据
     */
    private boolean hasNextPage(int size) {
        /**
         * 实际取到此分页的数据size是否等于约定的size
         */
        return size == HctConstants.PAGE_SIZE;
    }

    /**
     * 14、根据通知Id获取通知详情
     *
     * @param id
     * @return
     * @throws Exception
     */
    public HctResult getMessageById(String id) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("id", id));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_MESSAGE_MOBILE_PATH,
                        GET_MESSAGES_By_ID_ACTION, params) : controller
                .getMessageById();
        JSONObject jsonObject = new JSONObject(jsonString);

        MessagesEntity entity = MessagesEntity.parse(jsonObject);

        if (entity instanceof MessagesEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 15、提交App反馈
     *
     * @param personId
     * @param content
     * @return
     * @throws Exception
     */
    public HctResult submitReport(String personId, String content)
            throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("personId", personId));

        params.add(new BasicNameValuePair("content", content));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_REPORT_MOBILE_PATH,
                        SUBMIT_PEPORT_ACTION, params) : controller
                .submitReport();
        JSONObject jsonObject = new JSONObject(jsonString);

        ResultEntity entity = ResultEntity.parse(jsonObject);

        if (entity instanceof ResultEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 16、检查App版本
     *
     * @param clientVersion
     * @return
     * @throws Exception
     */
    public HctResult checkVersion(String clientVersion) throws Exception {
        HctResult result = new HctResult();
        HctBackTestJsonController controller = new HctBackTestJsonController(context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("clientVersion", clientVersion));
        /**
         * 0:android 1:IOS
         */
        params.add(new BasicNameValuePair("type", "0"));
        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_VERSION_MOBILE_PATH,
                        CHECK_VERSION_ACTION, params) : controller
                .checkVersion();
        JSONObject jsonObject = new JSONObject(jsonString);
        Log.i("update", "服务器APP版本" + jsonString);
        CheckVersionEntity entity = CheckVersionEntity.parse(jsonObject);
        if (entity instanceof CheckVersionEntity) {
            result.status = HctConstants.STATUS_SUCCESS;
            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    public HctResult getBookZipTxt(String filePath, String bookId)
            throws Exception {
        HctResult result = new HctResult();
        String sJson = BookZipTxtReaderUtil.readTxt(filePath, bookId);
        JSONObject jsonObject = new JSONObject(sJson);
        BookZipTxtEntity entity = BookZipTxtEntity.parse(jsonObject);
        if (entity instanceof BookZipTxtEntity) {
            if (entity != null) {
                insertBookZipTxtEntity2Db(entity, bookId);
            }
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 将获取到的"图书内的txt"插入db
     */
    private void insertBookZipTxtEntity2Db(BookZipTxtEntity bookZipTxtEntity,
                                           String bookId) {
        if (context != null) {
            /**
             * 插入db
             */
            DbEntryController dbController = new DbEntryController(context);
            dbController.insert(bookZipTxtEntity, bookId);
        } else {
            /**
             * 插入db
             */
            DbEntryController dbController = new DbEntryController(
                    mDbEntryAdapter);
            dbController.insert(bookZipTxtEntity, bookId);
        }

    }

    /**
     * 多本书的目录(模糊搜索)
     *
     * @param childSerieEntity
     * @param sSearchKey
     * @return
     * @throws Exception
     */
    public HctResult searchEntryMultiLevelCatalogList(
            final ChildSerieEntity childSerieEntity, final String sSearchKey)
            throws Exception {
        HctResult result = new HctResult();

        DbEntryController dbController = new DbEntryController(context);
        EntryCatalogEntity entity = dbController
                .getEntryMultiLevelCatalogEntity(childSerieEntity, sSearchKey);

        if (entity instanceof EntryCatalogEntity) {

            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 单本书的目录(模糊搜索)
     *
     * @param childSerieEntity
     * @param sSearchKey
     * @return
     * @throws Exception
     */
    public HctResult fuzzySearchEntryCatalogList(final String bookId,
                                                 final String sSearchKey) throws Exception {
        HctResult result = new HctResult();

        DbEntryController dbController = new DbEntryController(context);
        EntryCatalogEntity entity = dbController.fuzzySearchEntryCatalogEntity(
                bookId, sSearchKey);

        if (entity instanceof EntryCatalogEntity) {

            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    public HctResult getEntryCatalogList(String bookId, String titleContents)
            throws Exception {
        HctResult result = new HctResult();

        DbEntryController dbController = new DbEntryController(context);
        EntryCatalogEntity entity = dbController.getEntryCatalogEntity(bookId,
                titleContents);

        if (entity instanceof EntryCatalogEntity) {

            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    public HctResult getEntryContent(String bookId, String entryTitleId)
            throws Exception {
        HctResult result = new HctResult();

        DbEntryController dbController = new DbEntryController(context);
        EntryEntity entity = dbController.getEntryEntity(bookId, entryTitleId);

        if (entity instanceof EntryEntity) {

            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    public HctResult getMultiEntryContentLst(String bookId, String entryTitleId)
            throws Exception {
        HctResult result = new HctResult();

        DbEntryController dbController = new DbEntryController(context);
        BookZipTxtEntity entity = dbController.getMultiEntryEntityLst(bookId,
                entryTitleId);

        if (entity instanceof BookZipTxtEntity) {

            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 使用KeyWord模糊搜索MachineList
     *
     * @param keyWord
     * @return
     * @throws Exception
     */
    public HctResult fuzzySearchMachineList(String keyWord) throws Exception {
        HctResult result = new HctResult();

        MachineListEntity listEntity = new MachineListEntity();
        listEntity.dataList = fuzzySearchMachineListFromDb(keyWord);

        if (listEntity.dataList != null) {
            result.status = HctConstants.STATUS_SUCCESS;
            if (listEntity.dataList.size() > 0) {

                result.data = listEntity.dataList;
                result.totalSize = listEntity.dataList.size();
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    private List<MachineEntity> fuzzySearchMachineListFromDb(String keyWord) {
        /**
         * 插入db
         */
        DbController dbController = new DbController(context);
        return dbController.fuzzySearchMachineListEntity(keyWord).dataList;
    }

    /**
     * 获取Gif图片id及说明文字
     *
     * @return
     * @throws Exception
     */
    public HctResult getLoadingInfo() throws Exception {
        HctResult result = new HctResult();

        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        String jsonString = mServerAdapter.invokeServerGet(HctConstants.NET_LOADING_MOBILE_PATH,
                GET_LOADING_INFO_ACTION, params);
        JSONObject jsonObject = new JSONObject(jsonString);

        LoadingInfoEntity entity = LoadingInfoEntity.parse(jsonObject);

        if (entity instanceof LoadingInfoEntity) {
            result.status = HctConstants.STATUS_SUCCESS;
            result.data = entity;
            LogUtil.e("HctController", "getLoadingInfo:" + JSON.toJSONString(entity));
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 获取基本数据版本号
     *
     * @return
     * @throws Exception
     */
    public HctResult getDataVersionCode() throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_SYNC_DATA_MOBILE_PATH,
                        GET_DATA_VERSION_CODE_ACTION, params) : controller
                .getDataVersionCode();
        JSONObject jsonObject = new JSONObject(jsonString);

        DataVersionCodeEntity entity = DataVersionCodeEntity.parse(jsonObject);

        if (entity instanceof DataVersionCodeEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 20160608 390694添加 获取书籍资料版本号
     *
     * @return
     * @throws Exception
     */
    public HctResult getBookDataVersionCode() throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_SYNC_DATA_MOBILE_PATH,
                        GET_BOOK_DATA_VERSION_CODE_ACTION, params) : controller
                .getBookDataVersionCode();
        JSONObject jsonObject = new JSONObject(jsonString);

        DataVersionCodeEntity entity = DataVersionCodeEntity.parse(jsonObject);

        if (entity instanceof DataVersionCodeEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 调试维修栏目信息
     */
    public HctResult getAllColumns(boolean bTopRefresh) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);

        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        ColumnListEntity listEntity = null;
        if (!bTopRefresh) {
            /**
             * 首先尝试从db中查询
             */
            ArrayList<ColumnEntity> cEntities = selectColumnListFromDb();

            if (cEntities.size() > 0) {
                listEntity = new ColumnListEntity();
                listEntity.dataList = cEntities;
            }

            /**
             * 查询不到则从服务器获取
             */
            if (listEntity == null || listEntity.dataList == null
                    || listEntity.dataList.size() == 0) {
                listEntity = getAllColumnsFromNetAndInsert2Db(controller,
                        params);
            }
        } else if (bTopRefresh) {
            listEntity = getAllColumnsFromNetAndInsert2Db(controller, params);
        }
        if (listEntity.dataList != null) {
            result.status = HctConstants.STATUS_SUCCESS;
            if (listEntity.dataList.size() > 0) {

                result.data = listEntity.dataList;
                result.totalSize = listEntity.dataList.size();
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }

        return result;
    }

    private ColumnListEntity getAllColumnsFromNetAndInsert2Db(
            HctBackTestJsonController controller,
            ArrayList<NameValuePair> params) throws Exception, JSONException {
        ColumnListEntity listEntity;
        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_SYNC_DATA_MOBILE_PATH,
                        GET_ALL_COLUMNS_ACTION, params) : controller
                .getAllColumns();

        JSONObject jsonObject = new JSONObject(jsonString);

        listEntity = ColumnListEntity.parse(jsonObject, context);

        if (listEntity.dataList != null) {
            insertColumnList2Db(listEntity);
        }
        return listEntity;
    }

    /**
     * 从db查询出"调试维修栏目"
     *
     * @return
     */
    private ArrayList<ColumnEntity> selectColumnListFromDb() {
        /**
         * 插入db
         */
        DbColumnController dbController = new DbColumnController(context);
        return dbController.getColumnEntityLst();
    }

    /**
     * 将获取到的"调试维修栏目"插入db
     */
    private void insertColumnList2Db(ColumnListEntity listEntity) {
        /**
         * 插入db
         */
        DbColumnController dbController = new DbColumnController(context);
        dbController.insert(listEntity);
    }

    /**
     * 调试维修栏目信息(from db)
     *
     * @return
     * @throws Exception
     */
    public HctResult getAllColumnsFromDb(MachineEntity entity, String sKeyword)
            throws Exception {
        HctResult result = new HctResult();

        ColumnListEntity listEntity = new ColumnListEntity();

        /**
         * 首先尝试从db中查询
         */
        ArrayList<ColumnEntity> cEntities = selectColumnListFromDb();
        if (cEntities.size() > 0) {

            for (ColumnEntity cEntity : cEntities) {

                DbController dbController = new DbController(context);
                cEntity.dataList = dbController
                        .getBookLstUseColumnIdAndMachineId(entity, cEntity.id,
                                sKeyword);
            }
            listEntity.dataList = cEntities;

        }

        if (listEntity.dataList != null) {
            result.status = HctConstants.STATUS_SUCCESS;
            if (listEntity.dataList.size() > 0) {

                result.data = listEntity.dataList;
                result.totalSize = listEntity.dataList.size();
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 获取资讯内容(支持机型)
     *
     * @return
     * @throws Exception
     */
    public HctResult getContentByInfoType(String type) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        /**
         * Android_Support:android IOS_Support:IOS
         */
        params.add(new BasicNameValuePair("infoType", type));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_INFO_MOBILE_PATH,
                        GET_CONTENT_BY_INFO_TYPE_ACTION, params) : controller
                .getContentByInfoType();
        JSONObject jsonObject = new JSONObject(jsonString);

        SupportMidEntity entity = SupportMidEntity.parse(jsonObject);

        if (entity instanceof SupportMidEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 资料阅读统计
     *
     * @param bookName
     * @return
     * @throws Exception
     */
    public HctResult addClickCount(String bookName) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("bookName", bookName));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_STATISTICS_MOBILE_PATH,
                        ADD_CLICK_COUNT_ACTION, params) : controller
                .addClickCount();
        JSONObject jsonObject = new JSONObject(jsonString);

        ResultEntity entity = ResultEntity.parse(jsonObject);

        if (entity instanceof ResultEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 视频点击记录
     *
     * @param personId
     * @param videoPartId
     * @return
     * @throws Exception
     */
    public HctResult addVideoPlayRecord(String videoPartId, String personId) throws Exception {
        HctResult res = getStudyByPersonId();
        HctResult result = new HctResult();
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("videoPartId", videoPartId));
        params.add(new BasicNameValuePair("personId", personId));

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        String jsonString = mServerAdapter
                .invokeServerGet(HctConstants.TOKEN_STATISTICS_MOBILE,
                        HctConstants.ADD_VIDEO_PLAY_RECORD, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {


            result.status = HctConstants.STATUS_SUCCESS;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 视频播放统计
     *
     * @param videoPartId 视频剧集id
     * @return
     * @throws Exception
     */
    public HctResult addVideoPalyCount(String videoPartId) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("videoPartId", videoPartId));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_STATISTICS_MOBILE_PATH,
                        ADD_VIDEO_PLAY_COUNT_ACTION, params) : controller
                .addClickCount();
        JSONObject jsonObject = new JSONObject(jsonString);

        ResultEntity entity = ResultEntity.parse(jsonObject);

        if (entity instanceof ResultEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 视频下载记录
     *
     * @param videoPartId
     * @param personId
     * @return
     * @throws Exception
     */
    public HctResult addVideoDownloadRecord(String videoPartId, String personId) throws Exception {
        HctResult res = getStudyByPersonId();
        HctResult result = new HctResult();
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("videoPartId", videoPartId));
        params.add(new BasicNameValuePair("personId", personId));

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        String jsonString = mServerAdapter
                .invokeServerGet(HctConstants.TOKEN_STATISTICS_MOBILE,
                        HctConstants.ADD_VIDEO_DOWNDOAD_RECORD, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {


            result.status = HctConstants.STATUS_SUCCESS;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 视频下载统计
     *
     * @param videoPartId 视频剧集id
     * @return
     * @throws Exception
     */
    public HctResult addVideoDownloadCount(String videoPartId) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("videoPartId", videoPartId));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_STATISTICS_MOBILE_PATH,
                        ADD_VIDEO_DOWNLOAD_COUNT_ACTION, params) : controller
                .addClickCount();
        JSONObject jsonObject = new JSONObject(jsonString);

        ResultEntity entity = ResultEntity.parse(jsonObject);

        if (entity instanceof ResultEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 获取机型对应资料阅读数
     *
     * @param machineId
     * @return
     * @throws Exception
     */
    public HctResult getBookClick(String machineId) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("machineId", machineId));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_SYNC_DATA_MOBILE_PATH,
                        GET_BOOK_CLICK_ACTION, params) : controller
                .getBookClick();
        JSONObject jsonObject = new JSONObject(jsonString);

        BookClickListEntity entity = BookClickListEntity.parse(jsonObject);

        if (entity instanceof BookClickListEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 获取所有books并插入DB。
     *
     * @param bTopRefresh
     * @param type
     * @return
     * @throws Exception
     * @机制：如果是顶部刷新，先从DB获取，获取不到再访问服务器；如果不是顶部刷新直接访问服务器获取
     */
    public HctResult getAllBooksWithAllChildSeries2Db(boolean bTopRefresh,
                                                      int type) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);

        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        BookListEntity listEntity = null;
        /**
         * 首次加載先查DB
         */
        if (!bTopRefresh) {
            List<BookEntity> bookEntities = selectBookListFromDb(type).dataList;
            if (bookEntities != null && bookEntities.size() > 0) {
                listEntity = new BookListEntity();
                listEntity.dataList = bookEntities;
                // Log.i("hh", "查DB");
            }
            /**
             * 查詢不到在访问服务器
             */
            else {
                listEntity = getAllBooksFromNetAndInsert2Db(controller, params);
                // Log.i("hh", "查服务器");
            }
        } else if (bTopRefresh) {
            listEntity = getAllBooksFromNetAndInsert2Db(controller, params);
        }

        if (listEntity.dataList != null) {
            DownloadBookLstInitFinishUtil.saveDownloadBookFinished(context, true);
            result.status = HctConstants.STATUS_SUCCESS;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;

    }

    /**
     * 获取所有books并插入DB。
     *
     * @param bTopRefresh
     * @param type
     * @return ChildSerieEntity列表及BookEntity
     * @throws Exception
     * @机制：如果是顶部刷新，先从DB获取，获取不到再访问服务器；如果不是顶部刷新直接访问服务器获取
     */
    public HctResult getAllBooksWithAllChildSeriesAndDbSerieName(
            boolean bTopRefresh, int type) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);

        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        BookListEntity listEntity = null;
        /**
         * 首次加載先查DB
         */
        if (!bTopRefresh) {
            List<BookEntity> bookEntities = selectBookListFromDb(type).dataList;
            if (bookEntities != null && bookEntities.size() > 0) {
                listEntity = new BookListEntity();
                listEntity.dataList = bookEntities;
                //Log.i("hh", "查DB");
            }
            /**
             * 查詢不到在访问服务器
             */
            else {
                listEntity = getAllBooksFromNetAndInsert2Db(controller, params);
                //Log.i("hh", "查服务器");
            }
        } else if (bTopRefresh) {
            listEntity = getAllBooksFromNetAndInsert2Db(controller, params);
        }

        if (listEntity.dataList != null) {
            DownloadBookLstInitFinishUtil.saveInitFinished(context, true);
            result.status = HctConstants.STATUS_SUCCESS;
            if (listEntity.dataList.size() > 0) {

                List<SerieEntity> serieEntities = selectSerieListFromDb();

                List<ChildSerieEntity> childSerieEntities = null;
                if (serieEntities.size() > 0) {

                    childSerieEntities = new ArrayList<ChildSerieEntity>();
                    for (SerieEntity serieEntity : serieEntities) {

                        List<ChildSerieEntity> list = getChildSerieListEntityAndBooksUseSerieId(serieEntity.id);
                        if (list != null) {
                            ChildSerieEntity cEntity = list.get(0);
                            cEntity.seriesName = serieEntity.name;
                            cEntity.childSeriesCount = list.size();
                            childSerieEntities.addAll(list);
                        } else if (list == null) {
                            ChildSerieEntity cEntity = new ChildSerieEntity();
                            cEntity.seriesName = serieEntity.name;
                            cEntity.childSeriesCount = -1;
                            childSerieEntities.add(cEntity);
                        }

                    }
                }

                result.data = childSerieEntities;
                result.totalSize = childSerieEntities.size();
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;

    }

    /**
     * 下载管理
     *
     * @param bTopRefresh
     * @param type        0 全部 1已下载
     * @return
     * @throws Exception
     */
    public HctResult getSortChildSeriesAndDbSerieName(boolean bTopRefresh,
                                                      int type) throws Exception {
        HctResult result = new HctResult();
        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);

        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        Log.d("HctController", "开始从服务器获取All Books，然后insert 到Db");
        BookListEntity listEntity = null;
        //从数据库查询所有的系列数据
        List<SerieEntity> serieEntities = selectSerieListFromDb();
        if (!bTopRefresh) {
            List<BookEntity> bookEntities = selectBookListFromDb(type).dataList;
            if (bookEntities != null && bookEntities.size() > 0) {
                listEntity = new BookListEntity();
                listEntity.dataList = bookEntities;
            } else {
                if (type == 0) {
                    listEntity = getAllBooksFromNetAndInsert2Db(controller,
                            params);
                } else {
                    listEntity = new BookListEntity();
                    listEntity.dataList = new ArrayList<BookListEntity.BookEntity>();
                }
            }

        } else if (bTopRefresh) {
            if (type == 0) {
                listEntity = getAllBooksFromNetAndInsert2Db(controller, params);
            } else {
                List<BookEntity> bookEntities = selectBookListFromDb(type).dataList;
                if (bookEntities != null && bookEntities.size() > 0) {
                    listEntity = new BookListEntity();
                    listEntity.dataList = bookEntities;
                } else {
                    listEntity = new BookListEntity();
                    listEntity.dataList = new ArrayList<BookListEntity.BookEntity>();
                }
            }
        }
        if (listEntity.dataList != null) {
            DownloadBookLstInitFinishUtil.saveInitFinished(context, true);
            result.status = HctConstants.STATUS_SUCCESS;
            List<ChildSerieEntity> cList = getSortChildSerieEntity(
                    serieEntities, listEntity.dataList, type);
            result.data = cList;
            result.totalSize = cList.size();
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 下载资料模块数据组装
     *
     * @param serieEntities 所有系列
     * @param bookEntities  type对应的书籍
     * @param type          0 全部 1已下载
     * @return
     */

    private List<ChildSerieEntity> getSortChildSerieEntity(
            List<SerieEntity> serieEntities, List<BookEntity> bookEntities,
            int type) {
        List<ChildSerieEntity> cList = new ArrayList<ChildSerieEntity>();
        for (SerieEntity serieEntity : serieEntities) {

            //查询该系列下的子系列
            List<ChildSerieEntity> list = getChildSerieListEntityUseSerieId(
                    serieEntity.id, type);// 此处待优化，for循环中查询数据库效率较低，有望改成连接查询
            if (list != null) {
                ChildSerieEntity cEntity = list.get(0);
                cEntity.seriesName = serieEntity.name;
                cEntity.childSeriesCount = list.size();
                for (ChildSerieEntity bean : list) {
                    clearDeprecateBookIdList(bookEntities, bean);
                    // 当子系列下的书籍数不为0时，添加该子系列到结果中
                    if (bean.childSeriesBookIdList.size() != 0) {
                        // System.out.println(bean.seriesName+";"+bean.childSeriesName+";"+"childSeriesCount:"+bean.childSeriesCount+";childSeriesBookIdList:"+bean.childSeriesBookIdList.size());
                        cList.add(bean);
                    }
                }
                // cList.addAll(list);
                if (type == 1) {// 已下载列表不显示木有下载书籍的子系列
                    List<ChildSerieEntity> removeList = new ArrayList<ChildSerieEntity>();
                    int count = list.size();

                    for (int i = 0; i < list.size(); i++) {
                        ChildSerieEntity childSerieEntity = list.get(i);
                        if (childSerieEntity.childSeriesBookIdList.isEmpty()) {
                            count--;
                            removeList.add(childSerieEntity);
                        }
                    }
                    cList.removeAll(removeList);
                    if (count != 0) {
                        cEntity = cList.get(0);
                        cEntity.seriesName = serieEntity.name;
                        cEntity.childSeriesCount = count;
                    }
                }

            } else if (list == null) {
                if (type == 0) {// 全部资料才显示
                    ChildSerieEntity cEntity = new ChildSerieEntity();
                    cEntity.seriesName = serieEntity.name;
                    cEntity.childSeriesCount = -1;
                    cList.add(cEntity);
                }
            }
        }
        return cList;
    }

    /**
     * 清除"books"比"childSeriesBookIdList"少掉的bookId
     *
     * @param bookEntities
     * @param cEntity
     */
    private void clearDeprecateBookIdList(List<BookEntity> bookEntities,
                                          ChildSerieEntity cEntity) {
        List<String> deprecatedList = new ArrayList<String>();
        for (String childSeriesBookId : cEntity.childSeriesBookIdList) {
            boolean bDeprecated = true;
            for (BookEntity inNetEntity : bookEntities) {

                if (childSeriesBookId.equals(inNetEntity.id)) {
                    bDeprecated = false;
                }
            }
            if (bDeprecated) {
                deprecatedList.add(childSeriesBookId);
            }

        }
        cEntity.childSeriesBookIdList.removeAll(deprecatedList);
    }

    /**
     * 获取单条系列的子系列，不带书
     *
     * @param machineEntity
     * @return
     * @throws Exception
     */
    public HctResult getDbSingleSeriesWithDbChildSeries(String seriesId)
            throws Exception {
        HctResult result = new HctResult();
        SerieEntity entity = selectSerieEntityFromDb(seriesId);
        if (entity != null) {
            entity.childList = getChildSerieListEntityUseSerieId(seriesId, 0);
        }

        if (entity instanceof SerieEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 资料下载统计
     *
     * @param context
     * @param bookName
     * @return
     * @throws Exception
     */

    public HctResult addDownloadCount(Context context, String bookName)
            throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("bookName", bookName));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_STATISTICS_MOBILE_PATH,
                        ADD_DOWNLOAD_COUNT_ACTION, params) : controller
                .addDownloadCount();
        JSONObject jsonObject = new JSONObject(jsonString);

        ResultEntity entity = ResultEntity.parse(jsonObject);

        if (entity instanceof ResultEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 提交积分
     *
     * @param personId
     * @param points   可转int
     * @return
     * @throws Exception
     */

    public HctResult submitPoint(Context context, String personId, String points)
            throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("points", points));
        params.add(new BasicNameValuePair("personId", personId));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_POINT_MOBILE_PATH,
                        SUBMIT_POINT_ACTION, params) : controller
                .addDownloadCount();
        JSONObject jsonObject = new JSONObject(jsonString);

        PersonPotinsEntity entity = PersonPotinsEntity.parse(jsonObject);

        if (entity != null && entity.statusCode.equals("0")) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * @param fiveCode条码前5位
     * @return
     * @throws Exception
     */
    public HctResult getMachineAttr(Context context, String fiveCode)
            throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("fiveCode", fiveCode));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_BOOT_MOBILE_PATH,
                        GET_MACHINE_ATTR_ACTION, params) : controller
                .addDownloadCount();

        // Log.i("DATA", "家用热水机  配套水箱 HctResult --" + jsonString);

        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("bootStatus").equals("0")) {
            JSONArray jsonArray = jsonObject.getJSONArray("attrList");
            if (jsonArray != null && jsonArray.length() > 0) {
                List<AttrEntity> attrEntities = new ArrayList<AttrEntity>();
                attrEntities.add(new AttrEntity(null, "请选择"));
                for (int i = 0; i < jsonArray.length(); i++) {
                    attrEntities.add(AttrEntity.parse(jsonArray
                            .getJSONObject(i)));
                }
                result.status = HctConstants.STATUS_SUCCESS;
                result.data = attrEntities;
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }

        return result;
    }

    /**
     * 获取用户登陆积分
     */
    public HctResult getLoginPoints(String personId) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("personId", personId));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_PERSON_MOBILE_PATH,
                        GET_LOGIN_POINT, params) : controller.appLogin();
        JSONObject jsonObject = new JSONObject(jsonString);

        // LoginResultEntity entity = LoginResultEntity.parse(jsonObject);
        PersonPotinsEntity potinsEntity = PersonPotinsEntity.parse(jsonObject);

        if (potinsEntity instanceof PersonPotinsEntity) {
            result.status = HctConstants.STATUS_SUCCESS;
            result.data = potinsEntity;
            PersonPointsStoreUtil.save(context, potinsEntity);
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 获取学习资料类型 getAllStudyType
     */
    public HctResult getAllStudyType() throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_TRAIN_MOBILE_PATH, GET_ALL_STUDY_TYPE, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {
            JSONArray jsonArray = jsonObject.getJSONArray("studytypes");
            if (jsonArray != null && jsonArray.length() > 0) {
                List<AttrEntity> attrEntities = new ArrayList<AttrEntity>();
                for (int i = 0; i < jsonArray.length(); i++) {
                    attrEntities.add(AttrEntity.parse(jsonArray
                            .getJSONObject(i)));
                }
                result.status = HctConstants.STATUS_SUCCESS;
                result.data = attrEntities;
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 获取资料小类别id
     *
     * @param studytypeId 大类别id
     * @return
     * @throws Exception
     */
    public HctResult getChildTypeByTypeId(String studytypeId) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("studytypeId", studytypeId));
        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_TRAIN_MOBILE_PATH, GET_CHILD_TYPE_BY_TYPE_ID,
                params);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {
            JSONArray jsonArray = jsonObject.getJSONArray("childtypes");
            if (jsonArray != null && jsonArray.length() > 0) {
                List<AttrEntity> attrEntities = new ArrayList<AttrEntity>();
                for (int i = 0; i < jsonArray.length(); i++) {
                    attrEntities.add(AttrEntity.parse(jsonArray
                            .getJSONObject(i)));
                }
                result.status = HctConstants.STATUS_SUCCESS;
                result.data = attrEntities;
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    public HctResult addDownloadRecord(String bookName, String personId) throws Exception {
        HctResult res = getStudyByPersonId();
        HctResult result = new HctResult();
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("bookName", bookName));
        params.add(new BasicNameValuePair("personId", personId));

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        String jsonString = mServerAdapter
                .invokeServerGet(HctConstants.TOKEN_STATISTICS_MOBILE,
                        HctConstants.ADD_DOWNLOAD_RECORD, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {


            result.status = HctConstants.STATUS_SUCCESS;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 资料点击记录
     *
     * @param bookName
     * @param personId
     * @return
     * @throws Exception
     */
    public HctResult addClickRecord(String bookName, String personId) throws Exception {
        HctResult res = getStudyByPersonId();
        HctResult result = new HctResult();
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("bookName", bookName));
        params.add(new BasicNameValuePair("personId", personId));

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        String jsonString = mServerAdapter
                .invokeServerGet(HctConstants.TOKEN_STATISTICS_MOBILE,
                        HctConstants.ADD_CLICK_RECORD, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {


            result.status = HctConstants.STATUS_SUCCESS;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 新学员培训--学习资料列表
     * 含personId
     *
     * @return
     * @throws Exception
     */
    public HctResult getNewStudyDataListByPersonId(String studytypeId, String childtypeId,
                                                   String keywords, String type, String pageNum, String personId) throws Exception {
        //根据ID查询进行过点赞的资料列表
        HctResult res = getStudyByPersonId();
        HctResult result = new HctResult();
        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        LoginResultEntity resultEntity = LoginResultStoreUtil.get(context);

        params.add(new BasicNameValuePair("studytypeId", studytypeId));
        params.add(new BasicNameValuePair("childtypeId", childtypeId));
        params.add(new BasicNameValuePair("keywords", keywords));
        params.add(new BasicNameValuePair("type", type));
        params.add(new BasicNameValuePair("pageNum", pageNum));
        params.add(new BasicNameValuePair("pageSize", "20"));
        params.add(new BasicNameValuePair("personId", personId));
        String jsonString = mServerAdapter.invokeServerGet(HctConstants.TOKEN_TRAIN_MOBILE,
                HctConstants.GET_NEW_STUDY_DATA_LIST_BY_PERSONID, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {
            JSONArray jsonArray = jsonObject.getJSONArray("studydataList");
            if (jsonArray != null && jsonArray.length() > 0) {
                List<StudyEntity> attrEntities = new ArrayList<StudyEntity>();
                for (int i = 0; i < jsonArray.length(); i++) {
                    attrEntities.add(StudyEntity.parse(jsonArray.getJSONObject(i)));
                }
                result.status = HctConstants.STATUS_SUCCESS;
                result.data = attrEntities;
                List<StudyEntity> entity = (List<StudyEntity>) res.data;
                if (entity != null) {
                    for (int i = 0; i < attrEntities.size(); i++) {
                        for (int j = 0; j < entity.size(); j++) {
                            if (attrEntities.get(i).id.equals(entity.get(j).id)) {
                                attrEntities.get(i).setEvaluate(entity.get(j).getEvaluate());
                            }
                        }
                    }
                }
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 新学员培训--学习资料列表
     *
     * @return
     * @throws Exception
     */
    public HctResult getNewPersonStudyDataList(String studytypeId, String childtypeId,
                                               String keywords, String type, String pageNum, String trainType) throws Exception {
        //根据ID查询进行过点赞的资料列表
        HctResult res = getStudyByPersonId();
        HctResult result = new HctResult();
        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        LoginResultEntity resultEntity = LoginResultStoreUtil.get(context);

        params.add(new BasicNameValuePair("studytypeId", studytypeId));
        params.add(new BasicNameValuePair("childtypeId", childtypeId));
        params.add(new BasicNameValuePair("keywords", keywords));
        params.add(new BasicNameValuePair("type", type));
        params.add(new BasicNameValuePair("pageNum", pageNum));
        params.add(new BasicNameValuePair("pageSize", "20"));
        params.add(new BasicNameValuePair("trainType", trainType));
        //拼接一个personId
        params.add(new BasicNameValuePair("personId", ContantsUtil.sPersonId));

        String jsonString = mServerAdapter.invokeServerGet(HctConstants.TOKEN_TRAIN_MOBILE,
                HctConstants.GET_NEW_PERSON_STUDY_DATALIST, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {
            JSONArray jsonArray = jsonObject.getJSONArray("studydataList");
            if (jsonArray != null && jsonArray.length() > 0) {
                List<StudyEntity> attrEntities = new ArrayList<StudyEntity>();
                for (int i = 0; i < jsonArray.length(); i++) {
                    attrEntities.add(StudyEntity.parse(jsonArray.getJSONObject(i)));
                }
                result.status = HctConstants.STATUS_SUCCESS;
                result.data = attrEntities;
                List<StudyEntity> entity = (List<StudyEntity>) res.data;
                if (entity != null) {
                    for (int i = 0; i < attrEntities.size(); i++) {
                        for (int j = 0; j < entity.size(); j++) {
                            if (attrEntities.get(i).id.equals(entity.get(j).id)) {
                                attrEntities.get(i).setEvaluate(entity.get(j).getEvaluate());
                            }
                        }
                    }
                }
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }


    /**
     * 学习资料列表
     *
     * @param studytypeId 资料类别id
     * @param childtypeId 些列id
     * @param keywords    搜索关键字
     * @param type        类型 1发布时间 2 下载量 3点赞
     * @param pageNum     页码 默认一页20条 最小值为1
     * @return
     * @throws Exception
     */
    public HctResult getStudyDataList(String studytypeId, String childtypeId,
                                      String keywords, String type, String pageNum) throws Exception {
        //根据ID查询进行过点赞的资料列表
        HctResult res = getStudyByPersonId();
        HctResult result = new HctResult();
        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        LoginResultEntity resultEntity = LoginResultStoreUtil.get(context);

        params.add(new BasicNameValuePair("studytypeId", studytypeId));
        params.add(new BasicNameValuePair("childtypeId", childtypeId));
        params.add(new BasicNameValuePair("keywords", keywords));
        params.add(new BasicNameValuePair("type", type));
        params.add(new BasicNameValuePair("pageNum", pageNum));
        params.add(new BasicNameValuePair("pageSize", "20"));
        String jsonString = mServerAdapter.invokeServerGet(HctConstants.NET_TRAIN_MOBILE_PATH, GET_STUDY_DATA_LIST, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {
            JSONArray jsonArray = jsonObject.getJSONArray("studydataList");
            if (jsonArray != null && jsonArray.length() > 0) {
                List<StudyEntity> attrEntities = new ArrayList<StudyEntity>();
                for (int i = 0; i < jsonArray.length(); i++) {
                    attrEntities.add(StudyEntity.parse(jsonArray.getJSONObject(i)));
                }
                result.status = HctConstants.STATUS_SUCCESS;
                result.data = attrEntities;
                List<StudyEntity> entity = (List<StudyEntity>) res.data;
                if (entity != null) {
                    for (int i = 0; i < attrEntities.size(); i++) {
                        for (int j = 0; j < entity.size(); j++) {
                            if (attrEntities.get(i).id.equals(entity.get(j).id)) {
                                attrEntities.get(i).setEvaluate(entity.get(j).getEvaluate());
                            }
                        }
                    }
                }
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 2016 11 24
     * 通过用户ID获取当前所有培训学习资料是否进行过点击操作
     */
    public HctResult getStudyByPersonId() {

        HctResult result = new HctResult();
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        LoginResultEntity resultEntity = LoginResultStoreUtil.get(context);
        params.add(new BasicNameValuePair("personId", resultEntity.personId));
        try {
            String jsonString = mServerAdapter.invokeServerPost(
                    HctConstants.NET_TRAIN_MOBILE_PATH, GET_STUDY_BY_PERSON_ID_DATA_LIST, params);
            JSONObject jsonObject = new JSONObject(jsonString);
            if (jsonObject.getString("statusCode").equals("0")) {
                JSONArray jsonArray = jsonObject.getJSONArray("studydataList");
                if (jsonArray != null && jsonArray.length() > 0) {
                    List<StudyEntity> attrEntities = new ArrayList<StudyEntity>();
                    for (int i = 0; i < jsonArray.length(); i++) {
                        attrEntities.add(StudyEntity.parse(jsonArray
                                .getJSONObject(i)));
                    }

                    result.status = HctConstants.STATUS_SUCCESS;
                    result.data = attrEntities;
                } else {
                    result.status = HctConstants.STATUS_FAILD;
                }
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }


        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 获取学习资料详情
     *
     * @param id 学习资料id
     * @return
     * @throws Exception
     */
    public HctResult getStudyDetail(String id) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("id", id));
        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_TRAIN_MOBILE_PATH, GET_MESSAGE_BY_ID, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {
            result.status = HctConstants.STATUS_SUCCESS;
            result.data = StudyEntity.parse(jsonObject);
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 获取考试板块（考试搜索页面）
     */
    public HctResult getExamModule() throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_EXAM_MOBILE_PATH, GET_EXAM_MODULE, params);
        LogUtil.d(TAG, "jsonString = " + jsonString);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {
            JSONArray jsonArray = jsonObject.getJSONArray("data");
            if (jsonArray != null && jsonArray.length() > 0) {
                List<AttrEntity> attrEntities = new ArrayList<AttrEntity>();
                for (int i = 0; i < jsonArray.length(); i++) {
                    attrEntities.add(AttrEntity.parse(jsonArray
                            .getJSONObject(i)));
                }
                result.status = HctConstants.STATUS_SUCCESS;
                result.data = attrEntities;
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 获取考试的系列（考试搜索与页面）
     */
    public HctResult getExamSeries(String id) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("moduleId", id));
        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_EXAM_MOBILE_PATH, GET_EXAM_SERIES, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {
            JSONArray jsonArray = jsonObject.getJSONArray("data");
            if (jsonArray != null && jsonArray.length() > 0) {
                List<AttrEntity> attrEntities = new ArrayList<AttrEntity>();
                for (int i = 0; i < jsonArray.length(); i++) {
                    attrEntities.add(AttrEntity.parse(jsonArray
                            .getJSONObject(i)));
                }
                result.status = HctConstants.STATUS_SUCCESS;
                result.data = attrEntities;
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 获取试卷列表 getExamPagesList.do
     *
     * @param moduleId
     * @param seriesId
     * @param name
     * @return {@link List<ExamPaperEntity>}
     * @throws Exception
     * @since V2.3.0
     */
    public HctResult getExamPagesList(String moduleId, String seriesId,
                                      String name) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("examPage.moduleId", moduleId));
        params.add(new BasicNameValuePair("examPage.seriesId", seriesId));
        params.add(new BasicNameValuePair("examPage.name", name));
        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_EXAM_MOBILE_PATH, GET_EXAMPAGES_LIST, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {
            JSONArray jsonArray = jsonObject.getJSONArray("data");
            if (jsonArray != null && jsonArray.length() > 0) {
                List<ExamPaperEntity> entities = new ArrayList<ExamPaperEntity>();
                for (int i = 0; i < jsonArray.length(); i++) {
                    entities.add(ExamPaperEntity.getInstance().parse(jsonArray
                            .getJSONObject(i)));
                }
                result.status = HctConstants.STATUS_SUCCESS;
                result.data = entities;
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * http://192.168.0.100:9999/gree/exam-mobile!getExamPageById.do
     * pageId=402880964e059165014e0594045e0002
     */
    /**
     * @param pageId 试卷id
     * @return
     * @throws Exception
     */
    public HctResult getExamPageByID(String pageId) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("pageId", pageId));
        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_EXAM_MOBILE_PATH, GET_EXAMPAGE_BY_ID, params);
        LogUtil.d(TAG, "getExamPageById = " + GET_EXAMPAGE_BY_ID + "\n" +
                "jsonString = " + jsonString);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {

            if (jsonObject.has("data")) {
                result.status = HctConstants.STATUS_SUCCESS;
                result.data = ExamPaperEntity.getInstance().parse(jsonObject
                        .getJSONObject("data"));
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 获取试题列表
     *
     * @param pageId 试卷id
     * @return {@link List<ExamSubEntity>}试卷下的所有试题
     * @throws Exception {@link JSONException}
     * @since V2.3.0
     */

    public HctResult getExamPageSub(String pageId) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("pageId", pageId));
        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_EXAM_MOBILE_PATH, GET_EXAM_PAGE_SUB, params);
        LogUtil.i("EXAM", "考试---" + jsonString);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {
            JSONArray jsonArray = jsonObject.getJSONArray("data");
            if (jsonArray != null && jsonArray.length() > 0) {
                List<ExamSubEntity> entities = new ArrayList<ExamSubEntity>();
                for (int i = 0; i < jsonArray.length(); i++) {
                    entities.add(ExamSubEntity.parse(jsonArray.getJSONObject(i)));
                }
                result.status = HctConstants.STATUS_SUCCESS;
                result.data = entities;
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 提交试卷
     *
     * @param personId 会员id
     * @param pageId   试卷id
     * @param score    分数
     * @param remark   北备注
     * @param isPass   是否通过 0表示未通过 1表示通过
     * @return
     * @throws Exception
     */
    public HctResult addSco(String personId, String pageId, String score,
                            String remark, String isPass) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("examPersonPage.personId", personId));

        params.add(new BasicNameValuePair("examPersonPage.pageId", pageId));

        params.add(new BasicNameValuePair("examPersonPage.score", score));
        if (!TextUtils.isEmpty(remark)) {
            params.add(new BasicNameValuePair("examPersonPage.remark", remark));
        }
        params.add(new BasicNameValuePair("examPersonPage.isPass", isPass));

        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_EXAM_MOBILE_PATH, SUBMIT_PAGE, params);
        JSONObject jsonObject = new JSONObject(jsonString);

        ResultEntity entity = ResultEntity.parse(jsonObject);

        if (entity != null) {
            result.status = HctConstants.STATUS_SUCCESS;
            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * @param personId
     * @return
     * @throws Exception
     */

    public HctResult getPersonRecord(String personId) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("personId", personId));
        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_EXAM_MOBILE_PATH, GET_PERSON_RECORD, params);
        //Log.i("DATA", " 考试记录"+jsonString);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {
            JSONArray jsonArray = jsonObject.getJSONArray("data");
            if (jsonArray != null && jsonArray.length() > 0) {
                List<ExamPaperEntity> entities = new ArrayList<ExamPaperEntity>();
                for (int i = 0; i < jsonArray.length(); i++) {
                    entities.add(ExamPaperEntity.getInstance().parse(jsonArray
                            .getJSONObject(i)));
                }
                result.status = HctConstants.STATUS_SUCCESS;
                result.data = entities;
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 获取会员答题的条目
     *
     * @param personId
     * @return
     * @throws Exception
     */
    public HctResult getPersonRecordNum(String personId) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("personId", personId));

        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_EXAM_MOBILE_PATH, GET_PERSON_RECORD_NUM,
                params);
        JSONObject jsonObject = new JSONObject(jsonString);

        if ("0".equals(jsonObject.getString("statusCode"))
                && jsonObject.has("data")) {
            result.status = HctConstants.STATUS_SUCCESS;
            result.data = jsonObject.getInt("data");
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 6.16、新增我的收藏
     *
     * @param userId
     * @param contextId
     * @return
     * @throws Exception
     */
    public HctResult addCol(String userId, String contextId) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("userId", userId));

        params.add(new BasicNameValuePair("contextId", contextId));

        String jsonString = mServerAdapter.invokeServerGet("", "", params);
        JSONObject jsonObject = new JSONObject(jsonString);

        ResultEntity entity = ResultEntity.parse(jsonObject);

        if (entity instanceof ResultEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 6.18、删除收藏或清空收藏内容
     *
     * @param userId
     * @param contextId
     * @return
     * @throws Exception
     */
    public HctResult delCol(String userId, String contextId) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("userId", userId));

        if (!contextId.equals("")) {
            params.add(new BasicNameValuePair("contextId", contextId));
        }

        String jsonString = mServerAdapter.invokeServerGet("", "", params);
        JSONObject jsonObject = new JSONObject(jsonString);

        ResultEntity entity = ResultEntity.parse(jsonObject);

        if (entity instanceof ResultEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * {@link }
     *
     * @param barCodeId 条码前5位
     * @param personId  用户id
     * @return 安装信息列表
     * @throws Exception
     */
    public HctResult getSetupInfoList(String barCodeId, String personId)
            throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("barCodeId", barCodeId));
        params.add(new BasicNameValuePair("personId", personId));
        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_BOOT_MOBILE_PATH, GET_SETUPINFO_LIST, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {
            JSONArray jsonArray = jsonObject.getJSONArray("bootList");
            if (jsonArray != null && jsonArray.length() > 0) {
                List<SetupInfoEntity> entities = new ArrayList<SetupInfoEntity>();
                for (int i = 0; i < jsonArray.length(); i++) {
                    entities.add(SetupInfoEntity.parse(jsonArray
                            .getJSONObject(i)));
                }
                result.status = HctConstants.STATUS_SUCCESS;
                result.data = entities;
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 8、提交竞品资料
     *
     * @param personId
     * @param brand
     * @param topic
     * @param content
     * @param filepaths
     * @return
     * @throws Exception
     */
    public HctResult submitVieinfo(String personId, String brand, String topic,
                                   String content, List<String> filepaths, List<String> videoPathes,
                                   String attachment) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("personId", personId));

        params.add(new BasicNameValuePair("brand", brand));

        params.add(new BasicNameValuePair("topic", topic));

        params.add(new BasicNameValuePair("content", content));
        // params.add(new BasicNameValuePair("applianceType", applianceType));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerPostPhoto(HctConstants.NET_VIEINFO_MOBILE_PATH,
                        SUBMIT_VIEINFO_ACTION, params, filepaths, videoPathes,
                        attachment) : controller.submitFeedBack();
        JSONObject jsonObject = new JSONObject(jsonString);

        ResultEntity entity = ResultEntity.parse(jsonObject);

        if (entity instanceof ResultEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 获取竞品资料
     *
     * @param personId
     * @return
     * @throws Exception
     */
    public HctResult getVieinfoJsonByPersonId(String personId, String pageNum)
            throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair(PAGE_SIZE, String
                .valueOf(HctConstants.PAGE_SIZE)));
        params.add(new BasicNameValuePair(PAGE_NUM, String.valueOf(pageNum)));

        params.add(new BasicNameValuePair("personId", personId));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_VIEINFO_MOBILE_PATH,
                        GET_VIEINFOJSONBY_PERSONID_ACTION, params) : controller
                .getFeedBackJsonByPersonId();
        JSONObject jsonObject = new JSONObject(jsonString);

        CompetInfoListEntity listEntity = CompetInfoListEntity
                .parse(jsonObject);

        if (listEntity.dataList != null) {
            result.status = HctConstants.STATUS_SUCCESS;
            if (listEntity.dataList.size() > 0) {
                result.phone = listEntity.phone;
                result.data = listEntity.dataList;
                if (hasNextPage(listEntity.dataList.size())) {
                    result.totalSize = Integer.MAX_VALUE;
                } else {
                    result.totalSize = listEntity.dataList.size();
                }

                // if (pageNum.equals("1")) {
                // DbFeedBackController dbFeedBackController = new
                // DbFeedBackController(
                // context);
                // dbFeedBackController.insert(listEntity);
                // }
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 20160909--390694 获取终端培训---学习资料类型 getAllStudyType
     */
    public HctResult getTerminalAllStudyType() throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_TERMINAL_TRAIN_MOBILE_PATH, GET_ALL_STUDY_TYPE, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {
            JSONArray jsonArray = jsonObject.getJSONArray("studytypes");
            if (jsonArray != null && jsonArray.length() > 0) {
                List<AttrEntity> attrEntities = new ArrayList<AttrEntity>();
                for (int i = 0; i < jsonArray.length(); i++) {
                    attrEntities.add(AttrEntity.parse(jsonArray
                            .getJSONObject(i)));
                }
                result.status = HctConstants.STATUS_SUCCESS;
                result.data = attrEntities;
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 20160909--390694 获取终端培训--产品信息资料小类别id
     *
     * @param studytypeId 大类别id
     * @return
     * @throws Exception
     */
    public HctResult getTerminalChildTypeByTypeId(String studytypeId)
            throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("studytypeId", studytypeId));
        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_TERMINAL_TRAIN_MOBILE_PATH, GET_CHILD_TYPE_BY_TYPE_ID,
                params);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {
            JSONArray jsonArray = jsonObject.getJSONArray("childtypes");
            if (jsonArray != null && jsonArray.length() >= 0) {
                //20161104 get data failed or no data
                if (jsonArray.length() == 0) {
                    //no data
                    result.status = HctConstants.STATUS_NO_DATA;
                } else {
                    List<AttrEntity> attrEntities = new ArrayList<AttrEntity>();
                    for (int i = 0; i < jsonArray.length(); i++) {
                        attrEntities.add(AttrEntity.parse(jsonArray
                                .getJSONObject(i)));
                    }
                    result.status = HctConstants.STATUS_SUCCESS;
                    result.data = attrEntities;
                }
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 201609012--390694
     * 终端培训
     * 用学习资料的ID或者的childSeriesId查询到Book List
     *
     * @param seriesId---学习资料id
     * @param childSeriesId----子系列Id
     * @param time----时间
     * @param themeWord---资料标题
     * @param keyWord----关键字
     * @return
     * @throws Exception
     */
    public HctResult getBooksUseIdForTerminalTrain(String studytypeId,
                                                   String childtypeId, String time, String themeWord, String keyWord, String type, String pageNum)
            throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);

        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("studytypeId", studytypeId));
        params.add(new BasicNameValuePair("childtypeId", childtypeId));
        params.add(new BasicNameValuePair("keywords", keyWord));
        params.add(new BasicNameValuePair("title", themeWord));
        params.add(new BasicNameValuePair("time", time));
        params.add(new BasicNameValuePair("type", type));
        params.add(new BasicNameValuePair("pageNum", pageNum));
        params.add(new BasicNameValuePair("pageSize", "20"));

        String jsonString = mServerAdapter
                .invokeServerGet(HctConstants.NET_TERMINAL_TRAIN_MOBILE_PATH,
                        GET_STUDY_DATA_LIST, params);

        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {
            JSONArray jsonArray = jsonObject.getJSONArray("studydataList");
            if (jsonArray != null && jsonArray.length() >= 0) {
                if (jsonArray.length() == 0) {
                    result.status = HctConstants.STATUS_NO_DATA;
                } else {
                    List<StudyEntity> attrEntities = new ArrayList<StudyEntity>();
                    for (int i = 0; i < jsonArray.length(); i++) {
                        attrEntities.add(StudyEntity.parse(jsonArray
                                .getJSONObject(i)));
                    }
                    result.status = HctConstants.STATUS_SUCCESS;
                    result.data = attrEntities;
                }
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 20160913--390694
     * 终端培训：获取最新学习资料列表
     *
     * @return
     * @throws Exception
     */
    public HctResult getRecentLearningData() throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);

        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        LoginResultEntity resultEntity = LoginResultStoreUtil.get(context);

        String first = "1";
        params.add(new BasicNameValuePair("personId", resultEntity.personId));
        params.add(new BasicNameValuePair("first", first));

        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_TERMINAL_TRAIN_MOBILE_PATH,
                        GET_STUDY_DATA_LIST, params) : controller
                .getRecentLearningData();

        //Log.i("DATA", "搜索最新资料："+jsonString);
        JSONObject jsonObject = new JSONObject(jsonString);

        if (jsonObject.getString("statusCode").equals("0")) {
            JSONArray jsonArray = jsonObject.getJSONArray("studydataList");
            if (jsonArray != null && jsonArray.length() > 0) {
                List<StudyEntity> attrEntities = new ArrayList<StudyEntity>();
                Log.e("pm", "recent data:" + jsonArray);
                for (int i = 0; i < jsonArray.length(); i++) {
                    attrEntities.add(StudyEntity.parse(jsonArray
                            .getJSONObject(i)));
                }
                result.status = HctConstants.STATUS_SUCCESS;
                result.data = attrEntities;
                result.totalSize = attrEntities.size();

            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 获取学习资料详情
     *
     * @param id 学习资料id
     * @return
     * @throws Exception
     */
    public HctResult getTerminalStudyDetail(String id) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("id", id));
        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_TERMINAL_TRAIN_MOBILE_PATH, GET_MESSAGE_BY_ID, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {
            result.status = HctConstants.STATUS_SUCCESS;
            result.data = StudyEntity.parse(jsonObject);
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }


    /**
     * 20160917--390694
     * 终端培训：获取考试板块（考试搜索页面）
     */
    public HctResult getTerminalExamModule() throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_TERMINAL_EXAM_MOBILE_PATH, GET_EXAM_MODULE, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {
            JSONArray jsonArray = jsonObject.getJSONArray("data");
            if (jsonArray != null && jsonArray.length() > 0) {
                List<AttrEntity> attrEntities = new ArrayList<AttrEntity>();
                for (int i = 0; i < jsonArray.length(); i++) {
                    attrEntities.add(AttrEntity.parse(jsonArray
                            .getJSONObject(i)));
                }
                result.status = HctConstants.STATUS_SUCCESS;
                result.data = attrEntities;
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 20160917--390694
     * 终端培训：获取考试的系列（考试搜索与页面）
     */
    public HctResult getTerminalExamSeries(String id) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("moduleId", id));
        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_TERMINAL_EXAM_MOBILE_PATH, GET_EXAM_SERIES, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {
            JSONArray jsonArray = jsonObject.getJSONArray("data");
            if (jsonArray != null && jsonArray.length() >= 0) {
                if (jsonArray.length() == 0) {
                    result.status = HctConstants.STATUS_NO_DATA;
                } else {
                    List<AttrEntity> attrEntities = new ArrayList<AttrEntity>();
                    for (int i = 0; i < jsonArray.length(); i++) {
                        attrEntities.add(AttrEntity.parse(jsonArray
                                .getJSONObject(i)));
                    }
                    result.status = HctConstants.STATUS_SUCCESS;
                    result.data = attrEntities;
                }
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 20160918--390694
     * 终端培训：获取试卷列表 getExamPagesList.do
     *
     * @param examPage .moduleId
     * @param examPage .seriesId
     * @param examPage .name
     * @return {@link List<ExamPaperEntity>}
     * @throws Exception
     * @since V2.4.1
     */
    public HctResult getTerminalExamPagesList(String studyTypeId, String childtypeId,
                                              String time, String keyWord) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("saleExamPage.moduleId", studyTypeId));
        params.add(new BasicNameValuePair("saleExamPage.seriesId", childtypeId));
        params.add(new BasicNameValuePair("saleExamPage.name", keyWord));
        params.add(new BasicNameValuePair("time", time));

        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_TERMINAL_EXAM_MOBILE_PATH, GET_EXAMPAGES_LIST, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        LogUtil.e("pm", "exam list:" + jsonObject);
        if (jsonObject.getString("statusCode").equals("0")) {
            JSONArray jsonArray = jsonObject.getJSONArray("data");
            if (jsonArray != null && jsonArray.length() >= 0) {
                if (jsonArray.length() == 0) {
                    result.status = HctConstants.STATUS_NO_DATA;
                } else {
                    List<ExamPaperEntity> entities = new ArrayList<ExamPaperEntity>();
                    for (int i = 0; i < jsonArray.length(); i++) {
                        entities.add(ExamPaperEntity.getInstance().parse(jsonArray
                                .getJSONObject(i)));
                    }
                    result.status = HctConstants.STATUS_SUCCESS;
                    result.data = entities;
                }
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 20160927--390694
     * 终端培训：获取最新考试试题
     *
     * @return
     * @throws Exception
     */
    public HctResult getRecentExamData() throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);

        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        LoginResultEntity resultEntity = LoginResultStoreUtil.get(context);

        String first = "1";
        params.add(new BasicNameValuePair("personId", resultEntity.personId));
        params.add(new BasicNameValuePair("first", first));

        String jsonString = mServerAdapter
                .invokeServerGet(HctConstants.NET_TERMINAL_EXAM_MOBILE_PATH,
                        GET_EXAMPAGES_LIST, params);

        LogUtil.e("pm", "recent exam list row row:" + jsonString);
        JSONObject jsonObject = new JSONObject(jsonString);
        LogUtil.e("pm", "recent exam list row:" + jsonObject);
        if (jsonObject.getString("statusCode").equals("0")) {
            JSONArray jsonArray = jsonObject.getJSONArray("data");
            LogUtil.e("pm", "recent exam list:" + jsonArray);
            if (jsonArray != null && jsonArray.length() > 0) {
                List<ExamPaperEntity> entities = new ArrayList<ExamPaperEntity>();
                for (int i = 0; i < jsonArray.length(); i++) {
                    entities.add(ExamPaperEntity.getInstance().parse(jsonArray
                            .getJSONObject(i)));
                }
                result.status = HctConstants.STATUS_SUCCESS;
                result.data = entities;
                result.totalSize = entities.size();
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 2016-9-20 390694
     * 终端培训：获取会员答题的条目
     *
     * @param personId
     * @return
     * @throws Exception
     */
    public HctResult getPersonRecordNumForTerminal(String personId) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("personId", personId));

        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_TERMINAL_EXAM_MOBILE_PATH, GET_PERSON_RECORD_NUM,
                params);
        JSONObject jsonObject = new JSONObject(jsonString);

        if ("0".equals(jsonObject.getString("statusCode"))
                && jsonObject.has("data")) {
            result.status = HctConstants.STATUS_SUCCESS;
            result.data = jsonObject.getInt("data");
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 终端培训：试卷详情
     *
     * @param pageId 试卷id
     * @return
     * @throws Exception
     */
    public HctResult getTerminalExamPageByID(String pageId) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("pageId", pageId));
        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_TERMINAL_EXAM_MOBILE_PATH, GET_EXAMPAGE_BY_ID, params);
        JSONObject jsonObject = new JSONObject(jsonString);
        LogUtil.e("pm", " exam related book:" + jsonObject);
        if (jsonObject.getString("statusCode").equals("0")) {

            if (jsonObject.has("data")) {
                result.status = HctConstants.STATUS_SUCCESS;
                result.data = ExamPaperEntity.getInstance().parse(jsonObject
                        .getJSONObject("data"));
                LogUtil.e("pm", "exam related book result:" + result.data);
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 终端培训：获取试题列表
     *
     * @param pageId 试卷id
     * @return {@link List<ExamSubEntity>}试卷下的所有试题
     * @throws Exception {@link JSONException}
     * @author 390694
     * @time 2016-9-22
     */

    public HctResult getTerminalExamPageSub(String pageId) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("pageId", pageId));
        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_TERMINAL_EXAM_MOBILE_PATH, GET_EXAM_PAGE_SUB, params);

        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {
            JSONArray jsonArray = jsonObject.getJSONArray("data");
            if (jsonArray != null && jsonArray.length() > 0) {
                List<ExamSubEntity> entities = new ArrayList<ExamSubEntity>();
                for (int i = 0; i < jsonArray.length(); i++) {
                    entities.add(ExamSubEntity.parse(jsonArray.getJSONObject(i)));
                }
                result.status = HctConstants.STATUS_SUCCESS;
                result.data = entities;
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }


    /**
     * 终端培训：考试历史记录
     *
     * @param personId
     * @return
     * @throws Exception
     * @time 2016-9-22
     * @author 390694
     */

    public HctResult getTerminalPersonRecord(String personId) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("personId", personId));
        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_TERMINAL_EXAM_MOBILE_PATH, GET_PERSON_RECORD, params);
        //Log.i("DATA", " 考试记录"+jsonString);
        JSONObject jsonObject = new JSONObject(jsonString);
        if (jsonObject.getString("statusCode").equals("0")) {
            JSONArray jsonArray = jsonObject.getJSONArray("data");
            if (jsonArray != null && jsonArray.length() > 0) {
                List<ExamPaperEntity> entities = new ArrayList<ExamPaperEntity>();
                for (int i = 0; i < jsonArray.length(); i++) {
                    entities.add(ExamPaperEntity.getInstance().parse(jsonArray
                            .getJSONObject(i)));
                }
                result.status = HctConstants.STATUS_SUCCESS;
                result.data = entities;
            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 终端培训：提交试卷
     *
     * @param personId 会员id
     * @param pageId   试卷id
     * @param score    分数
     * @param remark   备注
     * @param isPass   是否通过 0表示未通过 1表示通过
     * @return
     * @throws Exception
     * @author 390694
     * @time 2016-9-24
     */
    public HctResult addScoForTerminal(String personId, String pageId, String score,
                                       String remark, String isPass) throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("saleExamPersonPage.personId", personId));

        params.add(new BasicNameValuePair("saleExamPersonPage.pageId", pageId));

        params.add(new BasicNameValuePair("saleExamPersonPage.score", score));
        if (!TextUtils.isEmpty(remark)) {
            params.add(new BasicNameValuePair("saleExamPersonPage.remark", remark));
        }
        params.add(new BasicNameValuePair("saleExamPersonPage.isPass", isPass));

        String jsonString = mServerAdapter.invokeServerGet(
                HctConstants.NET_TERMINAL_EXAM_MOBILE_PATH, SUBMIT_PAGE, params);
        JSONObject jsonObject = new JSONObject(jsonString);

        ResultEntity entity = ResultEntity.parse(jsonObject);

        if (entity instanceof ResultEntity) {
            result.status = HctConstants.STATUS_SUCCESS;

            result.data = entity;
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }


    /**
     * 2016 11 18--390778
     * 培训：获取最新学习资料列表
     *
     * @return
     * @throws Exception
     */
    public HctResult getRecentStudyData() throws Exception {
        HctResult result = new HctResult();

        HctBackTestJsonController controller = new HctBackTestJsonController(
                context);

        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        LoginResultEntity resultEntity = LoginResultStoreUtil.get(context);
        String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                .invokeServerGet(HctConstants.NET_TRAIN_MOBILE_PATH,
                        GET_NEW_STUDY_DATA_LIST, params) : controller
                .getRecentLearningData();

        JSONObject jsonObject = new JSONObject(jsonString);

        if (jsonObject.getString("statusCode").equals("0")) {
            JSONArray jsonArray = jsonObject.getJSONArray("studydataList");
            if (jsonArray != null && jsonArray.length() > 0) {
                List<StudyEntity> attrEntities = new ArrayList<StudyEntity>();
                for (int i = 0; i < jsonArray.length(); i++) {
                    attrEntities.add(StudyEntity.parse(jsonArray
                            .getJSONObject(i)));
                }
                result.status = HctConstants.STATUS_SUCCESS;
                result.data = attrEntities;
                result.totalSize = attrEntities.size();

            } else {
                result.status = HctConstants.STATUS_FAILD;
            }
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }

    /**
     * 2016-11-24
     * 390694
     * 从服务器获取All Books
     *
     * @param controller
     * @return
     * @throws Exception
     * @throws JSONException
     */
    public HctResult getAllBooksFromNetOrDb(
            HctBackTestJsonController controller) throws Exception, JSONException {
        BookListEntity listEntity = null;
        HctResult result = new HctResult();
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("personId", LoginResultStoreUtil
                .get(context).personId));
        //先从DB获取
        List<BookEntity> bookEntitiesInDb = null;
        bookEntitiesInDb = selectBookListFromDb(0).dataList;
        if (bookEntitiesInDb != null && bookEntitiesInDb.size() > 0) {
            listEntity = new BookListEntity();
            //从数据库获取书
            listEntity.dataList = bookEntitiesInDb;

            List<ChildSerieEntity> childSerieEntityListInDb = getChildSerieListEntityUseSerieId("", 0);
            if (childSerieEntityListInDb != null && childSerieEntityListInDb.size() > 0)
                listEntity.childSeriesBooksList = childSerieEntityListInDb;
        } else {//没有再从服务器获取
            String jsonString = !controller.isB_DEBUG() ? mServerAdapter
                    .invokeServerGet(HctConstants.NET_SYNC_DATA_MOBILE_PATH,
                            GET_ALL_BOOKS_ACTION, params) : controller
                    .getAllBooks();
            JSONObject jsonObject = new JSONObject(jsonString);
            listEntity = BookListEntity.parse(jsonObject);


        }

        if (listEntity instanceof BookListEntity) {
            result.status = HctConstants.STATUS_SUCCESS;
            result.data = listEntity;
            result.totalSize = listEntity.dataList.size();
        } else {
            result.status = HctConstants.STATUS_FAILD;
        }
        return result;
    }
}